#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 EXIT_FAILURE;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int write_config_file(char *file_name) {
  FILE *file;
  file = fopen(file_name, "w");
  if (file == NULL) {
    printf("Failed to open %s.\n", file_name);
    return EXIT_FAILURE;
  }
  fprintf(file, "mapred.local.dir="
                "/tmp/test-task-controller"
                "/local-1");
  int i;
  for (i = 2; i < 5; ++i) {
    fprintf(file,
            ","
            "/tmp/test-task-controller"
            "/local-%d",
            i);
  }
  fprintf(file, "\n");
  fprintf(file, "hadoop.log.dir="
                "/tmp/test-task-controller"
                "/logs\n");
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<write_config_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118c <write_config_file+0x4c>
mov    -0x10(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <write_config_file+0xc6>
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x1c(%rbp)
cmpl   $0x5,-0x1c(%rbp)
jge    11d2 <write_config_file+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <write_config_file+0x65>
mov    -0x18(%rbp),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_config_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1208 <write_config_file+0xa8>
mov    %rax,%rbx
lea    0xe90(%rip),%rdi
mov    $0x32,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xeaa(%rip),%rbp
xor    %r14d,%r14d
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
lea    0xe81(%rip),%rdi
mov    $0x2e,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1221 <write_config_file+0xc1>
lea    0xdf3(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [20 x i8] c"Failed to open %s.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [51 x i8] c"mapred.local.dir=/tmp/test-task-controller/local-1\00"
@.str.3 = [36 x i8] c",/tmp/test-task-controller/local-%d\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [47 x i8] c"hadoop.log.dir=/tmp/test-task-controller/logs\0A\00"
define i32 @write_config_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %2
br label %34
14: ; preds = %1
%15 = load i32*, i32** %4
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %5
br label %17
17: ; preds = %24, %14
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 5
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = load i32, i32* %5
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %17
27: ; preds = %17
%28 = load i32*, i32** %4
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = load i32*, i32** %4
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %2
br label %34
34: ; preds = %27, %10
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [20 x i8] c"Failed to open %s.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [51 x i8] c"mapred.local.dir=/tmp/test-task-controller/local-1\00"
@.str.3 = [36 x i8] c",/tmp/test-task-controller/local-%d\00"
@.str.5 = [47 x i8] c"hadoop.log.dir=/tmp/test-task-controller/logs\0A\00"
define i32 @write_config_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @EXIT_FAILURE
br label %15
7: ; preds = %1
%8 = tail call i64 @fwrite(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i64 50, i64 1, i32* %2)
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 2)
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 3)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 4)
%12 = tail call i32 @fputc(i32 10, i32* %2)
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i64 46, i64 1, i32* %2)
%14 = tail call i32 @fclose(i32* %2)
br label %15
15: ; preds = %7, %4
%16 = phi i32 [ %6, %4 ], [ 0, %7 ]
ret i32 %16
}