#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 rand();
int rand_int() {
  size_t byteSize = sizeof(int);
  int val = 0;
  val = val | rand() % 0x7F;
  for (size_t i = 1; i < byteSize; i++) {
    val = val << 8;
    val = val | (rand() % 0xFF);
  }
  return val;
}


x86 assembly (clang, -O0):
<rand_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x4,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x7f,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
or     %edx,%eax
mov    %eax,-0xc(%rbp)
movq   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1191 <rand_int+0x81>
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
or     %edx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <rand_int+0x3c>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_int>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff81020409,%rax,%r14
shr    $0x20,%r14
add    %eax,%r14d
mov    %r14d,%ecx
shr    $0x1f,%ecx
shr    $0x6,%r14d
add    %ecx,%r14d
mov    %r14d,%ecx
shl    $0x7,%ecx
sub    %ecx,%r14d
add    %eax,%r14d
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%r15
shr    $0x20,%r15
add    %eax,%r15d
mov    %r15d,%ecx
shr    $0x1f,%ecx
shr    $0x7,%r15d
add    %ecx,%r15d
mov    %r15d,%ecx
shl    $0x8,%ecx
sub    %ecx,%r15d
add    %eax,%r15d
shl    $0x10,%r14d
shl    $0x8,%r15d
or     %r14d,%r15d
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
shr    $0x7,%ebx
add    %ecx,%ebx
mov    %ebx,%ecx
shl    $0x8,%ecx
sub    %ecx,%ebx
add    %eax,%ebx
or     %r15d,%ebx
shl    $0x8,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
movslq %eax,%rcx
imul   $0xffffffff80808081,%rcx,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x7,%eax
add    %edx,%eax
mov    %eax,%edx
shl    $0x8,%edx
sub    %edx,%eax
add    %ecx,%eax
or     %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @rand_int() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i64
store i64 4, i64* %1
store i32 0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (...) @rand()
%6 = srem i32 %5, 127
%7 = or i32 %4, %6
store i32 %7, i32* %2
store i64 1, i64* %3
br label %8
8: ; preds = %19, %0
%9 = load i64, i64* %3
%10 = load i64, i64* %1
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i32, i32* %2
%14 = shl i32 %13, 8
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 255
%18 = or i32 %15, %17
store i32 %18, i32* %2
br label %19
19: ; preds = %12
%20 = load i64, i64* %3
%21 = add i64 %20, 1
store i64 %21, i64* %3
br label %8
22: ; preds = %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
define i32 @rand_int() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 127
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 255
%5 = shl nsw i32 %2, 16
%6 = shl nsw i32 %4, 8
%7 = or i32 %5, %6
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 255
%10 = or i32 %9, %7
%11 = shl nsw i32 %10, 8
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 255
%14 = or i32 %13, %11
ret i32 %14
}