#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 random_int(int /*<<< orphan*/, int);
int /*<<< orphan*/ random_seed();
int /*<<< orphan*/ test_msg_end(int);
int /*<<< orphan*/ test_msg_start(char *);
int test_random() {
  int i, j, result = 0;
  test_msg_start("Test Random Number Generator - Integers 0 to 100");
  random_seed();
  j = 0;
  while (j < 100000) {
    i = random_int(0, 100);
    if (i < 0 || i > 100)
      result++;
    j++;
  }
  test_msg_end(result);
  return result;
}


x86 assembly (clang, -O0):
<test_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <test_msg_start@plt>
mov    $0x0,%al
call   1060 <random_seed@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    11b0 <test_random+0x70>
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <random_int@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1199 <test_random+0x59>
cmpl   $0x64,-0x4(%rbp)
jle    11a2 <test_random+0x62>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1169 <test_random+0x29>
mov    -0xc(%rbp),%edi
call   1030 <test_msg_end@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_random>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1040 <test_msg_start@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <random_seed@plt>
mov    $0x186a0,%ebp
nopl   (%rax)
xor    %edi,%edi
mov    $0x64,%esi
call   1050 <random_int@plt>
cmp    $0x65,%eax
sbb    $0xffffffff,%ebx
add    $0xffffffff,%ebp
jne    1160 <test_random+0x20>
mov    %ebx,%edi
call   1030 <test_msg_end@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Test Random Number Generator - Integers 0 to 100\00"
define i32 @test_random() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 @test_msg_start(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @random_seed()
store i32 0, i32* %2
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 100000
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = call i32 @random_int(i32 0, i32 100)
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp slt i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 100
br i1 %15, label %16, label %19
16: ; preds = %13, %9
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %6
22: ; preds = %6
%23 = load i32, i32* %3
%24 = call i32 @test_msg_end(i32 %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [49 x i8] c"Test Random Number Generator - Integers 0 to 100\00"
define i32 @test_random() {
%1 = tail call i32 @test_msg_start(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @random_seed()
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %9, %3 ]
%5 = phi i32 [ 0, %0 ], [ %10, %3 ]
%6 = tail call i32 @random_int(i32 0, i32 100)
%7 = icmp ugt i32 %6, 100
%8 = zext i1 %7 to i32
%9 = add nuw nsw i32 %4, %8
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 100000
br i1 %11, label %12, label %3
12: ; preds = %3
%13 = tail call i32 @test_msg_end(i32 %9)
ret i32 %9
}