#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rand();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int r, data_len = 100;
  char *filename = "job_file";
  srand(time(NULL));
  FILE *fp = NULL;
  fp = fopen(filename, "w");
  char str[6];
  fprintf(fp, "1 %d\n", data_len);
  while (data_len--) {
    r = rand() % 10000;
    sprintf(str, "%d ", r);
    fprintf(fp, str);
    memset(str, 0, 6);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0xc(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     123f <main+0xbf>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
lea    -0x26(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xdfb(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x26(%rbp),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x26(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
jmp    11e2 <main+0x62>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe64(%rip),%rdi
lea    0xe66(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
mov    $0x64,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffff9c,%ebp
lea    0xe44(%rip),%r14
lea    0x2(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   10a0 <rand@plt>
movslq %eax,%rdx
imul   $0x68db8bad,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
add    %ecx,%eax
imul   $0x2710,%eax,%eax
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <sprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1040 <memset@plt>
inc    %ebp
jne    11e0 <main+0x60>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"job_file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"1 %d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [6 x i8]
store i32 0, i32* %1
store i32 100, i32* %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %4
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
store i32* null, i32** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = load i32, i32* %3
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %18, %0
%15 = load i32, i32* %3
%16 = add nsw i32 %15, -1
store i32 %16, i32* %3
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %29
18: ; preds = %14
%19 = call i32 (...) @rand()
%20 = srem i32 %19, 10000
store i32 %20, i32* %2
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %2
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %5
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* %25)
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 6)
br label %14
29: ; preds = %14
%30 = load i32*, i32** %5
%31 = call i32 @fclose(i32* %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"job_file\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"1 %d\0A\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = tail call i32 @time(i32* null)
%3 = tail call i32 @srand(i32 %2)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%6 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 100)
br label %7
7: ; preds = %0, %7
%8 = phi i32 [ 100, %0 ], [ %9, %7 ]
%9 = add nsw i32 %8, -1
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 10000
%12 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* %5)
%14 = call i32 @memset(i8* %5, i32 0, i32 6)
%15 = icmp eq i32 %9, 0
br i1 %15, label %16, label %7
16: ; preds = %7
%17 = call i32 @fclose(i32* %4)
ret i32 0
}