#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
unsigned int *malloc(int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
unsigned int time(int /*<<< orphan*/ *);
int main() {
  unsigned int *mynum = malloc(sizeof(int));
  unsigned int seed = time(NULL);
  srand(seed);
  FILE *write_file = fopen("test_out.txt", "w");
  fprintf(
      write_file,
      "#==================================================================\n");
  fprintf(write_file, "# generator test  seed = %u\n", seed);
  fprintf(
      write_file,
      "#==================================================================\n");
  fprintf(write_file, "type: d\n");
  fprintf(write_file, "count: %d\n", 10000000);
  fprintf(write_file, "numbit: %d\n", 32);
  for (int i = 0; i < 10000000; i++) {
    *mynum = 2 * rand();
    if (rand() % 2 == 0)
      (*mynum)++;
    fprintf(write_file, "%u\n", *mynum);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <srand@plt>
lea    0xe68(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x989680,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe70(%rip),%rsi
mov    $0x20,%edx
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x989680,-0x24(%rbp)
jge    1290 <main+0x130>
mov    $0x0,%al
call   1080 <rand@plt>
mov    %eax,%ecx
shl    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    126a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1228 <main+0xc8>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1030 <srand@plt>
lea    0xe64(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
lea    0xe5d(%rip),%r15
mov    $0x44,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe86(%rip),%rsi
mov    %r12,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x44,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r12,%rcx
call   1080 <fwrite@plt>
lea    0xe7b(%rip),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1080 <fwrite@plt>
lea    0xe6b(%rip),%rsi
mov    $0x989680,%ebx
mov    %r12,%rdi
mov    $0x989680,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe5b(%rip),%rsi
mov    %r12,%rdi
mov    $0x20,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe2d(%rip),%r15
jmp    1264 <main+0xf4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
je     1282 <main+0x112>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
add    %eax,%ebp
xor    %eax,%eax
call   1090 <rand@plt>
test   $0x1,%al
jne    1250 <main+0xe0>
or     $0x1,%ebp
mov    %ebp,(%r14)
jmp    1250 <main+0xe0>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"test_out.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [69 x i8] c"#==================================================================\0A\00"
@.str.3 = [29 x i8] c"# generator test seed = %u\0A\00"
@.str.4 = [9 x i8] c"type: d\0A\00"
@.str.5 = [11 x i8] c"count: %d\0A\00"
@.str.6 = [12 x i8] c"numbit: %d\0A\00"
@.str.7 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @malloc(i32 4)
store i32* %6, i32** %2
%7 = call i32 @time(i32* null)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @srand(i32 %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32*, i32** %4
%14 = load i32, i32* %3
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %4
%17 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0))
%18 = load i32*, i32** %4
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32*, i32** %4
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 10000000)
%22 = load i32*, i32** %4
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 32)
store i32 0, i32* %5
br label %24
24: ; preds = %43, %0
%25 = load i32, i32* %5
%26 = icmp slt i32 %25, 10000000
br i1 %26, label %27, label %46
27: ; preds = %24
%28 = call i32 (...) @rand()
%29 = mul nsw i32 2, %28
%30 = load i32*, i32** %2
store i32 %29, i32* %30
%31 = call i32 (...) @rand()
%32 = srem i32 %31, 2
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32*, i32** %2
%36 = load i32, i32* %35
%37 = add i32 %36, 1
store i32 %37, i32* %35
br label %38
38: ; preds = %34, %27
%39 = load i32*, i32** %4
%40 = load i32*, i32** %2
%41 = load i32, i32* %40
%42 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %38
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %24
46: ; preds = %24
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [13 x i8] c"test_out.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [69 x i8] c"#==================================================================\0A\00"
@.str.3 = [29 x i8] c"# generator test seed = %u\0A\00"
@.str.4 = [9 x i8] c"type: d\0A\00"
@.str.5 = [11 x i8] c"count: %d\0A\00"
@.str.6 = [12 x i8] c"numbit: %d\0A\00"
@.str.7 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = tail call i32* @malloc(i32 4)
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @fwrite(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i64 68, i64 1, i32* %4)
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %2)
%7 = tail call i64 @fwrite(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.2, i64 0, i64 0), i64 68, i64 1, i32* %4)
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64 8, i64 1, i32* %4)
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 10000000)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 32)
br label %12
11: ; preds = %21
ret i32 0
12: ; preds = %0, %21
%13 = phi i32 [ 0, %0 ], [ %24, %21 ]
%14 = tail call i32 (...) @rand()
%15 = shl nsw i32 %14, 1
%16 = tail call i32 (...) @rand()
%17 = and i32 %16, 1
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = or i32 %15, 1
store i32 %20, i32* %1
br label %21
21: ; preds = %19, %12
%22 = phi i32 [ %20, %19 ], [ %15, %12 ]
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i32 %13, 1
%25 = icmp eq i32 %24, 10000000
br i1 %25, label %11, label %12
}