#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int RAND_MAX;
int atoi(char *);
int get_percent_ret(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  printf("The rand() RAND_MAX is: %d.\n", RAND_MAX);
  int i = 23;
  int j = 0;
  if (argc > 1 && 0 != argv[1][0]) {
    i = atoi(argv[1]);
  }
  for (j = 0; j < 10000; j++) {
    int percent = get_percent_ret(i);
    printf("Current number is %d, get_percent_ret = %d\n", i, percent);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x17,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    119a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     119a <main+0x6a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2710,-0x18(%rbp)
jge    11db <main+0xab>
mov    -0x14(%rbp),%edi
call   1030 <get_percent_ret@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <main+0x71>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x17,%ebx
cmp    $0x2,%ebp
jl     116a <main+0x3a>
mov    0x8(%r14),%rdi
cmpb   $0x0,(%rdi)
je     116a <main+0x3a>
call   1050 <atoi@plt>
mov    %eax,%ebx
mov    $0x2710,%ebp
lea    0xea7(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1030 <get_percent_ret@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1180 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"The rand() RAND_MAX is: %d.\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [44 x i8] c"Current number is %d, get_percent_ret = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @RAND_MAX
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 23, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %26
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 0, %19
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
br label %26
26: ; preds = %21, %13, %2
store i32 0, i32* %7
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %7
%29 = icmp slt i32 %28, 10000
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %6
%32 = call i32 @get_percent_ret(i32 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %6
%34 = load i32, i32* %8
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
br label %36
36: ; preds = %30
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %27
39: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@.str = [29 x i8] c"The rand() RAND_MAX is: %d.\0A\00"
@RAND_MAX = global i32 0
@.str.1 = [44 x i8] c"Current number is %d, get_percent_ret = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @RAND_MAX
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %6
%12 = tail call i32 @atoi(i8* %8)
br label %13
13: ; preds = %11, %6, %2
%14 = phi i32 [ %12, %11 ], [ 23, %6 ], [ 23, %2 ]
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %19, %15 ]
%17 = tail call i32 @get_percent_ret(i32 %14)
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %17)
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, 10000
br i1 %20, label %21, label %15
21: ; preds = %15
ret i32 0
}