Created
June 4, 2016 00:21
-
-
Save Ameobea/6b4a1b9a7e395f47b45b7e67325b5af8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'thing.c' | |
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
@.str = private unnamed_addr constant [43 x i8] c"Enter the last number (n) of the series\0A\00", align 1 | |
@.str1 = private unnamed_addr constant [3 x i8] c"%d\00", align 1 | |
@.str2 = private unnamed_addr constant [51 x i8] c"Error. You gave a negative number. Program ends.\0A\00", align 1 | |
@.str3 = private unnamed_addr constant [35 x i8] c"Input the number to be the power\0A\00", align 1 | |
@.str4 = private unnamed_addr constant [59 x i8] c"The sum of the 1-%d series of integers raised in %d is %d\00", align 1 | |
; Function Attrs: nounwind uwtable | |
define i32 @main() #0 { | |
%1 = alloca i32, align 4 | |
%e = alloca i32, align 4 | |
%n = alloca i32, align 4 | |
%i = alloca i32, align 4 | |
%S = alloca i32, align 4 | |
store i32 0, i32* %1 | |
store i32 0, i32* %S, align 4 | |
%2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([43 x i8]* @.str, i32 0, i32 0)) | |
%3 = call i32 (i8*, ...)* @__isoc99_scanf(i8* getelementptr inbounds ([3 x i8]* @.str1, i32 0, i32 0), i32* %n) | |
%4 = load i32* %n, align 4 | |
%5 = icmp sle i32 %4, 0 | |
br i1 %5, label %6, label %8 | |
; <label>:6 ; preds = %0 | |
%7 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([51 x i8]* @.str2, i32 0, i32 0)) | |
store i32 0, i32* %1 | |
br label %34 | |
; <label>:8 ; preds = %0 | |
%9 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([35 x i8]* @.str3, i32 0, i32 0)) | |
%10 = call i32 (i8*, ...)* @__isoc99_scanf(i8* getelementptr inbounds ([3 x i8]* @.str1, i32 0, i32 0), i32* %e) | |
%11 = load i32* %e, align 4 | |
%12 = icmp sle i32 %11, 0 | |
br i1 %12, label %13, label %15 | |
; <label>:13 ; preds = %8 | |
%14 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([51 x i8]* @.str2, i32 0, i32 0)) | |
store i32 0, i32* %1 | |
br label %34 | |
; <label>:15 ; preds = %8 | |
store i32 1, i32* %i, align 4 | |
br label %16 | |
; <label>:16 ; preds = %26, %15 | |
%17 = load i32* %i, align 4 | |
%18 = load i32* %n, align 4 | |
%19 = icmp sle i32 %17, %18 | |
br i1 %19, label %20, label %29 | |
; <label>:20 ; preds = %16 | |
%21 = load i32* %i, align 4 | |
%22 = load i32* %e, align 4 | |
%23 = call i32 @power(i32 %21, i32 %22) | |
%24 = load i32* %S, align 4 | |
%25 = add nsw i32 %24, %23 | |
store i32 %25, i32* %S, align 4 | |
br label %26 | |
; <label>:26 ; preds = %20 | |
%27 = load i32* %i, align 4 | |
%28 = add nsw i32 %27, 1 | |
store i32 %28, i32* %i, align 4 | |
br label %16 | |
; <label>:29 ; preds = %16 | |
%30 = load i32* %n, align 4 | |
%31 = load i32* %e, align 4 | |
%32 = load i32* %S, align 4 | |
%33 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([59 x i8]* @.str4, i32 0, i32 0), i32 %30, i32 %31, i32 %32) | |
store i32 0, i32* %1 | |
br label %34 | |
; <label>:34 ; preds = %29, %13, %6 | |
%35 = load i32* %1 | |
ret i32 %35 | |
} | |
declare i32 @printf(i8*, ...) #1 | |
declare i32 @__isoc99_scanf(i8*, ...) #1 | |
; Function Attrs: nounwind uwtable | |
define i32 @power(i32 %b, i32 %e) #0 { | |
%1 = alloca i32, align 4 | |
%2 = alloca i32, align 4 | |
%3 = alloca i32, align 4 | |
%power = alloca i32, align 4 | |
%i = alloca i32, align 4 | |
store i32 %b, i32* %2, align 4 | |
store i32 %e, i32* %3, align 4 | |
store i32 1, i32* %power, align 4 | |
%4 = load i32* %2, align 4 | |
%5 = icmp sle i32 %4, 0 | |
br i1 %5, label %6, label %7 | |
; <label>:6 ; preds = %0 | |
store i32 -1, i32* %1 | |
br label %25 | |
; <label>:7 ; preds = %0 | |
%8 = load i32* %3, align 4 | |
%9 = icmp sle i32 %8, 0 | |
br i1 %9, label %10, label %11 | |
; <label>:10 ; preds = %7 | |
store i32 -1, i32* %1 | |
br label %25 | |
; <label>:11 ; preds = %7 | |
store i32 1, i32* %i, align 4 | |
br label %12 | |
; <label>:12 ; preds = %20, %11 | |
%13 = load i32* %i, align 4 | |
%14 = load i32* %3, align 4 | |
%15 = icmp sle i32 %13, %14 | |
br i1 %15, label %16, label %23 | |
; <label>:16 ; preds = %12 | |
%17 = load i32* %2, align 4 | |
%18 = load i32* %power, align 4 | |
%19 = mul nsw i32 %18, %17 | |
store i32 %19, i32* %power, align 4 | |
br label %20 | |
; <label>:20 ; preds = %16 | |
%21 = load i32* %i, align 4 | |
%22 = add nsw i32 %21, 1 | |
store i32 %22, i32* %i, align 4 | |
br label %12 | |
; <label>:23 ; preds = %12 | |
%24 = load i32* %power, align 4 | |
store i32 %24, i32* %1 | |
br label %25 | |
; <label>:25 ; preds = %23, %10, %6 | |
%26 = load i32* %1 | |
ret i32 %26 | |
} | |
attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" } | |
!llvm.ident = !{!0} | |
!0 = metadata !{metadata !"Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment