#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 long INT_MAX;
unsigned long __rand32();
int rand();
int rand_bool();
unsigned int rand32(void) {
  unsigned long r = 0;
  r = __rand32();
  if (rand_bool()) {
    unsigned int i;
    unsigned int rounds;
    rounds = rand() % 3;
    for (i = 0; i < rounds; i++) {
      switch (rand_bool()) {
      case 0:
        r |= __rand32();
        break;
      case 1:
        r ^= __rand32();
        break;
      default:
        break;
      }
    }
  }
  if (rand_bool())
    r = INT_MAX - r;
  if (rand_bool())
    r |= (1L << 31);
  if (rand() % 100 < 25) {
    int _div = 1 << ((rand() % 4) + 1);
    r /= _div;
  }
  switch (rand() % 4) {
  case 0:
    r &= 0xff;
    break;
  case 1:
    r &= 0xffff;
    break;
  case 2:
    r &= 0xffffff;
    break;
  default:
    break;
  }
  return r;
}


x86 assembly (clang, -O0):
<rand32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <__rand32@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand_bool@plt>
cmp    $0x0,%eax
je     11ef <rand32+0xbf>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11ea <rand32+0xba>
xor    %eax,%eax
call   1050 <rand_bool@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
test   %eax,%eax
je     11aa <rand32+0x7a>
jmp    1199 <rand32+0x69>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     11be <rand32+0x8e>
jmp    11d2 <rand32+0xa2>
mov    $0x0,%al
call   1030 <__rand32@plt>
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <rand32+0xa7>
mov    $0x0,%al
call   1030 <__rand32@plt>
xor    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d7 <rand32+0xa7>
jmp    11d7 <rand32+0xa7>
jmp    11dc <rand32+0xac>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <rand32+0x44>
jmp    11ef <rand32+0xbf>
mov    $0x0,%al
call   1050 <rand_bool@plt>
cmp    $0x0,%eax
je     1211 <rand32+0xe1>
mov    0x2de2(%rip),%rax
mov    (%rax),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand_bool@plt>
cmp    $0x0,%eax
je     1233 <rand32+0x103>
movabs $0x80000000,%rax
or     -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x19,%edx
jge    127a <rand32+0x14a>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
add    $0x1,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rcx
mov    -0x8(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
call   1040 <rand@plt>
mov    %eax,%edx
add    $0x3,%edx
test   %eax,%eax
mov    %eax,%ecx
cmovs  %edx,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
je     12c2 <rand32+0x192>
jmp    12a0 <rand32+0x170>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     12d5 <rand32+0x1a5>
jmp    12b1 <rand32+0x181>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     12e8 <rand32+0x1b8>
jmp    12fb <rand32+0x1cb>
mov    -0x8(%rbp),%rax
and    $0xff,%rax
mov    %rax,-0x8(%rbp)
jmp    1300 <rand32+0x1d0>
mov    -0x8(%rbp),%rax
and    $0xffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1300 <rand32+0x1d0>
mov    -0x8(%rbp),%rax
and    $0xffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    1300 <rand32+0x1d0>
jmp    1300 <rand32+0x1d0>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand32>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <__rand32@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1050 <rand_bool@plt>
test   %eax,%eax
je     1172 <rand32+0x42>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
jne    1223 <rand32+0xf3>
xor    %eax,%eax
call   1050 <rand_bool@plt>
mov    0x2e68(%rip),%rcx
mov    (%rcx),%rbx
sub    %r14,%rbx
test   %eax,%eax
cmove  %r14,%rbx
xor    %eax,%eax
call   1050 <rand_bool@plt>
mov    $0x80000000,%r14d
or     %rbx,%r14
test   %eax,%eax
cmove  %rbx,%r14
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x18,%eax
jg     1249 <rand32+0x119>
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfc,%ecx
sub    %ecx,%eax
lea    0x1(%rax),%ecx
mov    $0x1,%esi
shl    %cl,%esi
movslq %esi,%rcx
mov    %r14,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     123f <rand32+0x10f>
mov    %r14,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%r14
jmp    1249 <rand32+0x119>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <__rand32@plt>
xor    %rax,%r14
add    $0xffffffff,%ebx
je     1172 <rand32+0x42>
xor    %eax,%eax
call   1050 <rand_bool@plt>
cmp    $0x1,%eax
je     1210 <rand32+0xe0>
test   %eax,%eax
jne    121a <rand32+0xea>
xor    %eax,%eax
call   1030 <__rand32@plt>
or     %rax,%r14
jmp    121a <rand32+0xea>
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%r14d
xor    %eax,%eax
call   1040 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cmp    $0x2,%eax
je     1271 <rand32+0x141>
cmp    $0x1,%eax
je     127a <rand32+0x14a>
test   %eax,%eax
jne    127e <rand32+0x14e>
movzbl %r14b,%r14d
jmp    127e <rand32+0x14e>
and    $0xffffff,%r14d
jmp    127e <rand32+0x14e>
movzwl %r14w,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @rand32() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i64 0, i64* %1
%5 = call i64 (...) @__rand32()
store i64 %5, i64* %1
%6 = call i32 (...) @rand_bool()
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %31
8: ; preds = %0
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 3
store i32 %10, i32* %3
store i32 0, i32* %2
br label %11
11: ; preds = %27, %8
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = call i32 (...) @rand_bool()
switch i32 %16, label %25 [
i32 0, label %17
i32 1, label %21
]
17: ; preds = %15
%18 = call i64 (...) @__rand32()
%19 = load i64, i64* %1
%20 = or i64 %19, %18
store i64 %20, i64* %1
br label %26
21: ; preds = %15
%22 = call i64 (...) @__rand32()
%23 = load i64, i64* %1
%24 = xor i64 %23, %22
store i64 %24, i64* %1
br label %26
25: ; preds = %15
br label %26
26: ; preds = %25, %21, %17
br label %27
27: ; preds = %26
%28 = load i32, i32* %2
%29 = add i32 %28, 1
store i32 %29, i32* %2
br label %11
30: ; preds = %11
br label %31
31: ; preds = %30, %0
%32 = call i32 (...) @rand_bool()
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i64, i64* @INT_MAX
%36 = load i64, i64* %1
%37 = sub i64 %35, %36
store i64 %37, i64* %1
br label %38
38: ; preds = %34, %31
%39 = call i32 (...) @rand_bool()
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i64, i64* %1
%43 = or i64 %42, 2147483648
store i64 %43, i64* %1
br label %44
44: ; preds = %41, %38
%45 = call i32 (...) @rand()
%46 = srem i32 %45, 100
%47 = icmp slt i32 %46, 25
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = call i32 (...) @rand()
%50 = srem i32 %49, 4
%51 = add nsw i32 %50, 1
%52 = shl i32 1, %51
store i32 %52, i32* %4
%53 = load i32, i32* %4
%54 = sext i32 %53 to i64
%55 = load i64, i64* %1
%56 = udiv i64 %55, %54
store i64 %56, i64* %1
br label %57
57: ; preds = %48, %44
%58 = call i32 (...) @rand()
%59 = srem i32 %58, 4
switch i32 %59, label %69 [
i32 0, label %60
i32 1, label %63
i32 2, label %66
]
60: ; preds = %57
%61 = load i64, i64* %1
%62 = and i64 %61, 255
store i64 %62, i64* %1
br label %70
63: ; preds = %57
%64 = load i64, i64* %1
%65 = and i64 %64, 65535
store i64 %65, i64* %1
br label %70
66: ; preds = %57
%67 = load i64, i64* %1
%68 = and i64 %67, 16777215
store i64 %68, i64* %1
br label %70
69: ; preds = %57
br label %70
70: ; preds = %69, %66, %63, %60
%71 = load i64, i64* %1
%72 = trunc i64 %71 to i32
ret i32 %72
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @rand32() {
%1 = tail call i64 (...) @__rand32()
%2 = tail call i32 (...) @rand_bool()
%3 = icmp eq i32 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %0
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 3
%7 = icmp eq i32 %6, 0
br i1 %7, label %22, label %8
8: ; preds = %4, %18
%9 = phi i64 [ %19, %18 ], [ %1, %4 ]
%10 = phi i32 [ %20, %18 ], [ 0, %4 ]
%11 = tail call i32 (...) @rand_bool()
switch i32 %11, label %18 [
i32 0, label %12
i32 1, label %15
]
12: ; preds = %8
%13 = tail call i64 (...) @__rand32()
%14 = or i64 %13, %9
br label %18
15: ; preds = %8
%16 = tail call i64 (...) @__rand32()
%17 = xor i64 %16, %9
br label %18
18: ; preds = %12, %15, %8
%19 = phi i64 [ %9, %8 ], [ %17, %15 ], [ %14, %12 ]
%20 = add nuw i32 %10, 1
%21 = icmp eq i32 %20, %6
br i1 %21, label %22, label %8
22: ; preds = %18, %4, %0
%23 = phi i64 [ %1, %0 ], [ %1, %4 ], [ %19, %18 ]
%24 = tail call i32 (...) @rand_bool()
%25 = icmp eq i32 %24, 0
%26 = load i64, i64* @INT_MAX
%27 = sub i64 %26, %23
%28 = select i1 %25, i64 %23, i64 %27
%29 = tail call i32 (...) @rand_bool()
%30 = icmp eq i32 %29, 0
%31 = or i64 %28, 2147483648
%32 = select i1 %30, i64 %28, i64 %31
%33 = tail call i32 (...) @rand()
%34 = srem i32 %33, 100
%35 = icmp slt i32 %34, 25
br i1 %35, label %36, label %43
36: ; preds = %22
%37 = tail call i32 (...) @rand()
%38 = srem i32 %37, 4
%39 = add nsw i32 %38, 1
%40 = shl nuw nsw i32 1, %39
%41 = sext i32 %40 to i64
%42 = udiv i64 %32, %41
br label %43
43: ; preds = %36, %22
%44 = phi i64 [ %42, %36 ], [ %32, %22 ]
%45 = tail call i32 (...) @rand()
%46 = srem i32 %45, 4
switch i32 %46, label %53 [
i32 0, label %47
i32 1, label %49
i32 2, label %51
]
47: ; preds = %43
%48 = and i64 %44, 255
br label %53
49: ; preds = %43
%50 = and i64 %44, 65535
br label %53
51: ; preds = %43
%52 = and i64 %44, 16777215
br label %53
53: ; preds = %43, %51, %49, %47
%54 = phi i64 [ %44, %43 ], [ %52, %51 ], [ %50, %49 ], [ %48, %47 ]
%55 = trunc i64 %54 to i32
ret i32 %55
}