#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 */
unsigned int get_interesting_32bit_value();
int rand();
unsigned long rand8x8();
unsigned long rand_single_bit(int);
unsigned long randbits(int);
unsigned long rept8(int);
unsigned long taviso();
unsigned int __rand32(void) {
  unsigned long r = 0;
  switch (rand() % 7) {
  case 0:
    r = rand_single_bit(32);
    break;
  case 1:
    r = randbits(32);
    break;
  case 2:
    r = rand();
    break;
  case 3:
    r = taviso();
    break;
  case 4:
    r = rand8x8();
    break;
  case 5:
    r = rept8(4);
    break;
  case 6:
    return get_interesting_32bit_value();
  default:
    break;
  }
  return r;
}


x86 assembly (clang, -O0):
<__rand32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x10(%rbp)
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x2,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x3,%edx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x6,%eax
ja     1247 <__rand32+0xd7>
mov    -0x18(%rbp),%rax
lea    0xe3c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x20,%edi
call   1060 <rand_single_bit@plt>
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x20,%edi
call   1050 <randbits@plt>
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x0,%al
call   1090 <rand@plt>
cltq
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x0,%al
call   1070 <taviso@plt>
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x0,%al
call   1030 <rand8x8@plt>
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x4,%edi
call   1080 <rept8@plt>
mov    %rax,-0x10(%rbp)
jmp    124c <__rand32+0xdc>
mov    $0x0,%al
call   1040 <get_interesting_32bit_value@plt>
mov    %eax,-0x4(%rbp)
jmp    1253 <__rand32+0xe3>
jmp    124c <__rand32+0xdc>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__rand32>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1090 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff92492493,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
lea    0x0(,%rax,8),%edx
sub    %edx,%eax
add    %ecx,%eax
cmp    $0x6,%eax
ja     11f6 <__rand32+0x86>
lea    0xe55(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x20,%edi
call   1060 <rand_single_bit@plt>
jmp    11f3 <__rand32+0x83>
mov    $0x20,%edi
call   1050 <randbits@plt>
jmp    11f3 <__rand32+0x83>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebx
jmp    11f6 <__rand32+0x86>
xor    %eax,%eax
call   1070 <taviso@plt>
jmp    11f3 <__rand32+0x83>
xor    %eax,%eax
call   1030 <rand8x8@plt>
jmp    11f3 <__rand32+0x83>
mov    $0x4,%edi
call   1080 <rept8@plt>
mov    %rax,%rbx
mov    %ebx,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
jmp    1040 <get_interesting_32bit_value@plt>

LLVM IR (-O0):
define i32 @__rand32() {
%1 = alloca i32
%2 = alloca i64
store i64 0, i64* %2
%3 = call i32 (...) @rand()
%4 = srem i32 %3, 7
switch i32 %4, label %20 [
i32 0, label %5
i32 1, label %7
i32 2, label %9
i32 3, label %12
i32 4, label %14
i32 5, label %16
i32 6, label %18
]
5: ; preds = %0
%6 = call i64 @rand_single_bit(i32 32)
store i64 %6, i64* %2
br label %21
7: ; preds = %0
%8 = call i64 @randbits(i32 32)
store i64 %8, i64* %2
br label %21
9: ; preds = %0
%10 = call i32 (...) @rand()
%11 = sext i32 %10 to i64
store i64 %11, i64* %2
br label %21
12: ; preds = %0
%13 = call i64 (...) @taviso()
store i64 %13, i64* %2
br label %21
14: ; preds = %0
%15 = call i64 (...) @rand8x8()
store i64 %15, i64* %2
br label %21
16: ; preds = %0
%17 = call i64 @rept8(i32 4)
store i64 %17, i64* %2
br label %21
18: ; preds = %0
%19 = call i32 (...) @get_interesting_32bit_value()
store i32 %19, i32* %1
br label %24
20: ; preds = %0
br label %21
21: ; preds = %20, %16, %14, %12, %9, %7, %5
%22 = load i64, i64* %2
%23 = trunc i64 %22 to i32
store i32 %23, i32* %1
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
define i32 @__rand32() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 7
switch i32 %2, label %18 [
i32 0, label %3
i32 1, label %5
i32 2, label %7
i32 3, label %10
i32 4, label %12
i32 5, label %14
i32 6, label %16
]
3: ; preds = %0
%4 = tail call i64 @rand_single_bit(i32 32)
br label %18
5: ; preds = %0
%6 = tail call i64 @randbits(i32 32)
br label %18
7: ; preds = %0
%8 = tail call i32 (...) @rand()
%9 = zext i32 %8 to i64
br label %18
10: ; preds = %0
%11 = tail call i64 (...) @taviso()
br label %18
12: ; preds = %0
%13 = tail call i64 (...) @rand8x8()
br label %18
14: ; preds = %0
%15 = tail call i64 @rept8(i32 4)
br label %18
16: ; preds = %0
%17 = tail call i32 (...) @get_interesting_32bit_value()
br label %21
18: ; preds = %0, %14, %12, %10, %7, %5, %3
%19 = phi i64 [ 0, %0 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ], [ %9, %7 ], [ %6, %5 ], [ %4, %3 ]
%20 = trunc i64 %19 to i32
br label %21
21: ; preds = %18, %16
%22 = phi i32 [ %20, %18 ], [ %17, %16 ]
ret i32 %22
}