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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, long);
int rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  long int i, n;
  FILE *fp;
  fp = fopen("data_decimal.in", "w");
  time_t t;
  n = 1000000;
  srand((unsigned)time(&t));
  for (i = 0; i < n; i++) {
    fprintf(fp, "%d", rand() % 10);
  }
  printf("\nCount %ld\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movq   $0xf4240,-0x18(%rbp)
lea    -0x24(%rbp),%rdi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11ec <main+0x8c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x30(%rbp),%rdi
mov    $0xa,%ecx
cltd
idiv   %ecx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a6 <main+0x46>
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe90(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0xf4240,%ebx
lea    0xe76(%rip),%r14
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <rand@plt>
movslq %eax,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fprintf@plt>
add    $0xffffffffffffffff,%rbx
jne    11a0 <main+0x40>
lea    0xe38(%rip),%rdi
mov    $0xf4240,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"data_decimal.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"\0ACount %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
store i64 1000000, i64* %3
%7 = call i64 @time(i32* %5)
%8 = trunc i64 %7 to i32
%9 = call i32 @srand(i32 %8)
store i64 0, i64* %2
br label %10
10: ; preds = %19, %0
%11 = load i64, i64* %2
%12 = load i64, i64* %3
%13 = icmp slt i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32*, i32** %4
%16 = call i32 (...) @rand()
%17 = srem i32 %16, 10
%18 = call i32 @fprintf(i32* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14
%20 = load i64, i64* %2
%21 = add nsw i64 %20, 1
store i64 %21, i64* %2
br label %10
22: ; preds = %10
%23 = load i64, i64* %2
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"data_decimal.in\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [12 x i8] c"\0ACount %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
%4 = call i64 @time(i32* %1)
%5 = trunc i64 %4 to i32
%6 = call i32 @srand(i32 %5)
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %12, %7 ]
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 10
%11 = call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 1000000
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 1000000)
ret i32 0
}