#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, int banned) {
  FILE *file;
  file = fopen(file_name, "w");
  if (file == NULL) {
    printf("Failed to open %s.\n", file_name);
    return EXIT_FAILURE;
  }
  if (banned != 0) {
    fprintf(file, "banned.users=bannedUser\n");
    fprintf(file, "min.user.id=500\n");
  } else {
    fprintf(file, "min.user.id=0\n");
  }
  fprintf(file, "allowed.system.users=allowedUser,daemon\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    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <write_config_file+0x4f>
mov    -0x10(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11ee <write_config_file+0xae>
cmpl   $0x0,-0x14(%rbp)
je     11be <write_config_file+0x7e>
mov    -0x20(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11ce <write_config_file+0x8e>
mov    -0x20(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%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    %esi,%ebp
mov    %rdi,%rbx
lea    0xeb0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1188 <write_config_file+0x48>
mov    %rax,%r14
test   %ebp,%ebp
je     11a2 <write_config_file+0x62>
lea    0xeae(%rip),%rdi
mov    $0x18,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
lea    0xeae(%rip),%rdi
mov    $0x10,%esi
jmp    11ae <write_config_file+0x6e>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
jmp    11de <write_config_file+0x9e>
lea    0xe97(%rip),%rdi
mov    $0xe,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
lea    0xe8d(%rip),%rdi
mov    $0x28,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%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 = [25 x i8] c"banned.users=bannedUser\0A\00"
@.str.3 = [17 x i8] c"min.user.id=500\0A\00"
@.str.4 = [15 x i8] c"min.user.id=0\0A\00"
@.str.5 = [41 x i8] c"allowed.system.users=allowedUser,daemon\0A\00"
define i32 @write_config_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %31
15: ; preds = %2
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32*, i32** %6
%20 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32*, i32** %6
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %26
23: ; preds = %15
%24 = load i32*, i32** %6
%25 = call i32 @fprintf(i32* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %23, %18
%27 = load i32*, i32** %6
%28 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %3
br label %31
31: ; preds = %26, %11
%32 = load i32, i32* %3
ret i32 %32
}

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 = [25 x i8] c"banned.users=bannedUser\0A\00"
@.str.3 = [17 x i8] c"min.user.id=500\0A\00"
@.str.4 = [15 x i8] c"min.user.id=0\0A\00"
@.str.5 = [41 x i8] c"allowed.system.users=allowedUser,daemon\0A\00"
define i32 @write_config_file(i8* %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @EXIT_FAILURE
br label %18
8: ; preds = %2
%9 = icmp eq i32 %1, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 24, i64 1, i32* %3)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 16, i64 1, i32* %3)
br label %15
13: ; preds = %8
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 14, i64 1, i32* %3)
br label %15
15: ; preds = %13, %10
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i64 40, i64 1, i32* %3)
%17 = tail call i32 @fclose(i32* %3)
br label %18
18: ; preds = %15, %5
%19 = phi i32 [ %7, %5 ], [ 0, %15 ]
ret i32 %19
}