#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, int);
int randi(int /*<<< orphan*/, int);
int test_randi(void) {
  int i;
  int retval;
  int counter_1 = 0;
  int counter_2 = 0;
  int counter_3 = 0;
  for (i = 0; i < 10000; i++) {
    retval = randi(0, 2);
    if (retval == 0) {
      counter_1++;
    } else if (retval == 1) {
      counter_2++;
    } else if (retval == 2) {
      counter_3++;
    }
  }
  printf("%d, %d, %d\n", counter_1, counter_2, counter_3);
  return 0;
}


x86 assembly (clang, -O0):
<test_randi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x2710,-0x4(%rbp)
jge    11c0 <test_randi+0xa0>
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <randi@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1178 <test_randi+0x58>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ad <test_randi+0x8d>
cmpl   $0x1,-0x8(%rbp)
jne    1190 <test_randi+0x70>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a8 <test_randi+0x88>
cmpl   $0x2,-0x8(%rbp)
jne    11a3 <test_randi+0x83>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <test_randi+0x88>
jmp    11ad <test_randi+0x8d>
jmp    11b2 <test_randi+0x92>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1144 <test_randi+0x24>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_randi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
mov    $0x2710,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1149 <test_randi+0x29>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r15d
add    $0xffffffff,%ebp
je     1176 <test_randi+0x56>
xor    %edi,%edi
mov    $0x2,%esi
call   1030 <randi@plt>
cmp    $0x2,%eax
je     1170 <test_randi+0x50>
cmp    $0x1,%eax
je     1140 <test_randi+0x20>
test   %eax,%eax
jne    1144 <test_randi+0x24>
add    $0x1,%ebx
jmp    1144 <test_randi+0x24>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
jmp    1144 <test_randi+0x24>
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%d, %d, %d\0A\00"
define i32 @test_randi() {
br label %1
1: ; preds = %0, %13
%2 = phi i32 [ 0, %0 ], [ %16, %13 ]
%3 = phi i32 [ 0, %0 ], [ %15, %13 ]
%4 = phi i32 [ 0, %0 ], [ %14, %13 ]
%5 = phi i32 [ 0, %0 ], [ %17, %13 ]
%6 = tail call i32 @randi(i32 0, i32 2)
switch i32 %6, label %13 [
i32 0, label %7
i32 1, label %9
i32 2, label %11
]
7: ; preds = %1
%8 = add nsw i32 %4, 1
br label %13
9: ; preds = %1
%10 = add nsw i32 %3, 1
br label %13
11: ; preds = %1
%12 = add nsw i32 %2, 1
br label %13
13: ; preds = %1, %7, %11, %9
%14 = phi i32 [ %8, %7 ], [ %4, %9 ], [ %4, %11 ], [ %4, %1 ]
%15 = phi i32 [ %3, %7 ], [ %10, %9 ], [ %3, %11 ], [ %3, %1 ]
%16 = phi i32 [ %2, %7 ], [ %2, %9 ], [ %12, %11 ], [ %2, %1 ]
%17 = add nuw nsw i32 %5, 1
%18 = icmp eq i32 %17, 10000
br i1 %18, label %19, label %1
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16)
ret i32 0
}