#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 /*<<< orphan*/ printf(char *, int, ...);
int rand();
int get_percent_ret(int percent) {
  if (percent >= 100) {
    return 1;
  }
  if (percent <= 0) {
    return 0;
  }
  int other = 100 - percent;
  int container[2];
  container[0] = other;
  container[1] = percent;
  int find = 0;
  int rand_index = rand() % 2;
  int rand_percent = rand() % 100;
  if (0 == rand_percent) {
    return 0;
  }
  int tmp_percent = 0;
  int i = 0;
  printf("rand_index = %d, rand_percent = %d%%\t", rand_index, rand_percent);
  for (; i < 2; i++) {
    tmp_percent += container[i];
    printf("tmp_percent = %d\t", tmp_percent);
    if (rand_percent <= tmp_percent) {
      find = i;
      break;
    }
  }
  return find;
}


x86 assembly (clang, -O0):
<get_percent_ret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jl     1141 <get_percent_ret+0x21>
movl   $0x1,-0x4(%rbp)
jmp    122b <get_percent_ret+0x10b>
cmpl   $0x0,-0x8(%rbp)
jg     1157 <get_percent_ret+0x37>
movl   $0x0,-0x4(%rbp)
jmp    122b <get_percent_ret+0x10b>
mov    $0x64,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%eax
jne    11b0 <get_percent_ret+0x90>
movl   $0x0,-0x4(%rbp)
jmp    122b <get_percent_ret+0x10b>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x28(%rbp)
jge    1225 <get_percent_ret+0x105>
movslq -0x28(%rbp),%rax
mov    -0x14(%rbp,%rax,4),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1212 <get_percent_ret+0xf2>
mov    -0x28(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1225 <get_percent_ret+0x105>
jmp    1217 <get_percent_ret+0xf7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d2 <get_percent_ret+0xb2>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_percent_ret>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x1,%ebx
cmp    $0x63,%edi
jg     11ce <get_percent_ret+0xae>
mov    %edi,%ebp
xor    %ebx,%ebx
test   %edi,%edi
jle    11ce <get_percent_ret+0xae>
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%r14
imul   $0x51eb851f,%r14,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%r14d
je     11ce <get_percent_ret+0xae>
mov    $0x64,%r12d
sub    %ebp,%r12d
mov    %r15d,%eax
shr    $0x1f,%eax
add    %r15d,%eax
and    $0xfffffffe,%eax
sub    %eax,%r15d
lea    0xe6f(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe7f(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %r12d,%r14d
jle    11ce <get_percent_ret+0xae>
lea    0xe69(%rip),%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"rand_index = %d, rand_percent = %d%%\09\00"
@.str.1 = [18 x i8] c"tmp_percent = %d\09\00"
define i32 @get_percent_ret(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = load i32, i32* %3
%12 = icmp sge i32 %11, 100
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %2
br label %59
14: ; preds = %1
%15 = load i32, i32* %3
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 0, i32* %2
br label %59
18: ; preds = %14
%19 = load i32, i32* %3
%20 = sub nsw i32 100, %19
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
store i32 %21, i32* %22
%23 = load i32, i32* %3
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
store i32 %23, i32* %24
store i32 0, i32* %6
%25 = call i32 (...) @rand()
%26 = srem i32 %25, 2
store i32 %26, i32* %7
%27 = call i32 (...) @rand()
%28 = srem i32 %27, 100
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp eq i32 0, %29
br i1 %30, label %31, label %32
31: ; preds = %18
store i32 0, i32* %2
br label %59
32: ; preds = %18
store i32 0, i32* %9
store i32 0, i32* %10
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %34)
br label %36
36: ; preds = %54, %32
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 2
br i1 %38, label %39, label %57
39: ; preds = %36
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %9
%45 = add nsw i32 %44, %43
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %8
%49 = load i32, i32* %9
%50 = icmp sle i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %39
%52 = load i32, i32* %10
store i32 %52, i32* %6
br label %57
53: ; preds = %39
br label %54
54: ; preds = %53
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %36
57: ; preds = %51, %36
%58 = load i32, i32* %6
store i32 %58, i32* %2
br label %59
59: ; preds = %57, %31, %17, %13
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@.str = [38 x i8] c"rand_index = %d, rand_percent = %d%%\09\00"
@.str.1 = [18 x i8] c"tmp_percent = %d\09\00"
define i32 @get_percent_ret(i32 %0) {
%2 = icmp sgt i32 %0, 99
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = icmp slt i32 %0, 1
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = sub nuw nsw i32 100, %0
%7 = tail call i32 (...) @rand()
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 100
%10 = icmp eq i32 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = srem i32 %7, 2
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %9)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%15 = icmp sgt i32 %9, %6
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 100)
br label %18
18: ; preds = %5, %16, %11, %3, %1
%19 = phi i32 [ 1, %1 ], [ 0, %3 ], [ 0, %5 ], [ 0, %11 ], [ 1, %16 ]
ret i32 %19
}