#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(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int writeFile(int **data, int len, int index) {
  FILE *fp;
  int i, j;
  char fname[10];
  sprintf(fname, "%d", index);
  fp = fopen(strcat(fname, ".uwv"), "w");
  if (fp == NULL)
    return -1;
  for (i = 0; i < len; i++) {
    for (j = 0; j < 3; j++) {
      fprintf(fp, "%d ", data[i][j]);
    }
    fprintf(fp, "\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<writeFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
lea    -0x32(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe90(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x32(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1060 <strcat@plt>
mov    %eax,%edi
lea    0xe7a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <writeFile+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <writeFile+0xe5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1225 <writeFile+0xd5>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    1205 <writeFile+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c8 <writeFile+0x78>
mov    -0x20(%rbp),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <writeFile+0x65>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xe88(%rip),%rsi
lea    0x6(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <sprintf@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe6d(%rip),%rsi
mov    %eax,%edi
call   1060 <fopen@plt>
test   %rax,%rax
je     121d <writeFile+0xbd>
mov    %rax,%rbx
test   %ebp,%ebp
jle    1211 <writeFile+0xb1>
mov    %ebp,%r12d
lea    0xe52(%rip),%r15
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbp,8),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14,%rbp,8),%rax
mov    0x4(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14,%rbp,8),%rax
mov    0x8(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11c0 <writeFile+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1222 <writeFile+0xc2>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c".uwv\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @writeFile(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [10 x i8]
store i32** %0, i32*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%13 = load i32, i32* %7
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @fopen(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %8
%18 = load i32*, i32** %8
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %54
21: ; preds = %3
store i32 0, i32* %9
br label %22
22: ; preds = %48, %21
%23 = load i32, i32* %9
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %51
26: ; preds = %22
store i32 0, i32* %10
br label %27
27: ; preds = %42, %26
%28 = load i32, i32* %10
%29 = icmp slt i32 %28, 3
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = load i32*, i32** %8
%32 = load i32**, i32*** %5
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32*, i32** %32, i64 %34
%36 = load i32*, i32** %35
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %30
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %27
45: ; preds = %27
%46 = load i32*, i32** %8
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %45
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %22
51: ; preds = %22
%52 = load i32*, i32** %8
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %4
br label %54
54: ; preds = %51, %20
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c".uwv\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d \00"
define i32 @writeFile(i32** nocapture %0, i32 %1, i32 %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
%7 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32* @fopen(i32 %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %33, label %10
10: ; preds = %3
%11 = icmp sgt i32 %1, 0
br i1 %11, label %12, label %31
12: ; preds = %10
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ 0, %12 ], [ %29, %14 ]
%16 = getelementptr inbounds i32*, i32** %0, i64 %15
%17 = load i32*, i32** %16
%18 = load i32, i32* %17
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32*, i32** %16
%21 = getelementptr inbounds i32, i32* %20, i64 1
%22 = load i32, i32* %21
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load i32*, i32** %16
%25 = getelementptr inbounds i32, i32* %24, i64 2
%26 = load i32, i32* %25
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = call i32 @fputc(i32 10, i32* %8)
%29 = add nuw nsw i64 %15, 1
%30 = icmp eq i64 %29, %13
br i1 %30, label %31, label %14
31: ; preds = %14, %10
%32 = call i32 @fclose(i32* %8)
br label %33
33: ; preds = %3, %31
%34 = phi i32 [ 0, %31 ], [ -1, %3 ]
ret i32 %34
}