#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, int);
int rand();
void generateMovesFile(int size) {
  FILE *f = fopen("moves", "w");
  int i;
  for (i = 0; i < size; i++)
    fprintf(f, "%d,%d\n", rand() % 7, rand() % 4);
  fclose(f);
}


x86 assembly (clang, -O0):
<generateMovesFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c1 <generateMovesFile+0x81>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    -0x20(%rbp),%rdi
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x18(%rbp),%edx
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1169 <generateMovesFile+0x29>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateMovesFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
lea    0xeb0(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r14
test   %ebp,%ebp
jle    11c3 <generateMovesFile+0x83>
lea    0xe9e(%rip),%r15
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
cltq
imul   $0xffffffff92492493,%rax,%rbx
shr    $0x20,%rbx
add    %eax,%ebx
mov    %ebx,%ecx
shr    $0x1f,%ecx
sar    $0x2,%ebx
add    %ecx,%ebx
lea    0x0(,%rbx,8),%ecx
sub    %ecx,%ebx
add    %eax,%ebx
xor    %eax,%eax
call   1060 <rand@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %eax,%ecx
call   1040 <fprintf@plt>
add    $0xffffffff,%ebp
jne    1170 <generateMovesFile+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"moves\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [7 x i8] c"%d,%d\0A\00"
define void @generateMovesFile(i32 %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %13
4: ; preds = %1, %4
%5 = phi i32 [ %11, %4 ], [ 0, %1 ]
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 7
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 4
%10 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %7, i32 %9)
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, %0
br i1 %12, label %13, label %4
13: ; preds = %4, %1
%14 = tail call i32 @fclose(i32* %2)
ret void
}