#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 FileWritePermissionCheck(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char const *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char const *, char *);
bool FileWrite(const char *file_name, const char *input_str, const char *mode) {
  FILE *file_point;
  if (strcmp(mode, "w") != 0 && strcmp(mode, "a") != 0 &&
      strcmp(mode, "w+") != 0 && strcmp(mode, "a+") != 0) {
    printf("FileWrite:mode ERROR!\n");
    return false;
  }
  if (strcmp(mode, "a") == 0 || strcmp(mode, "a+") == 0) {
    if (FileWritePermissionCheck(file_name) == false) {
      printf("FileWrite:permission ERROR!\n");
      return false;
    }
  }
  file_point = fopen(file_name, mode);
  fprintf(file_point, input_str);
  fclose(file_point);
  return true;
}


x86 assembly (clang, -O0):
<FileWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f4 <FileWrite+0x94>
mov    -0x20(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f4 <FileWrite+0x94>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f4 <FileWrite+0x94>
mov    -0x20(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11f4 <FileWrite+0x94>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <FileWrite+0x125>
mov    -0x20(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1228 <FileWrite+0xc8>
mov    -0x20(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1257 <FileWrite+0xf7>
mov    -0x10(%rbp),%rdi
call   1070 <FileWritePermissionCheck@plt>
cmp    $0x0,%eax
jne    1252 <FileWrite+0xf2>
lea    0xde0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1285 <FileWrite+0x125>
jmp    1257 <FileWrite+0xf7>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileWrite>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8b(%rip),%rsi
mov    %rdx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c7 <FileWrite+0x67>
lea    0xe79(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c7 <FileWrite+0x67>
lea    0xe67(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c7 <FileWrite+0x67>
lea    0xe56(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11c7 <FileWrite+0x67>
lea    0xe61(%rip),%rdi
jmp    122a <FileWrite+0xca>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ef <FileWrite+0x8f>
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11fb <FileWrite+0x9b>
mov    %r15,%rdi
call   1070 <FileWritePermissionCheck@plt>
test   %eax,%eax
je     1223 <FileWrite+0xc3>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    1231 <FileWrite+0xd1>
lea    0xde0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [3 x i8] c"a+\00"
@.str.4 = [23 x i8] c"FileWrite:mode ERROR!\0A\00"
@.str.5 = [29 x i8] c"FileWrite:permission ERROR!\0A\00"
define i32 @FileWrite(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %4
br label %50
26: ; preds = %20, %16, %12, %3
%27 = load i8*, i8** %7
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30, %26
%35 = load i8*, i8** %5
%36 = call i32 @FileWritePermissionCheck(i8* %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %4
br label %50
40: ; preds = %34
br label %41
41: ; preds = %40, %30
%42 = load i8*, i8** %5
%43 = load i8*, i8** %7
%44 = call i32* @fopen(i8* %42, i8* %43)
store i32* %44, i32** %8
%45 = load i32*, i32** %8
%46 = load i8*, i8** %6
%47 = call i32 @fprintf(i32* %45, i8* %46)
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
store i32 1, i32* %4
br label %50
50: ; preds = %41, %38, %24
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
@.str.2 = [3 x i8] c"w+\00"
@.str.3 = [3 x i8] c"a+\00"
@str = [28 x i8] c"FileWrite:permission ERROR!\00"
@str.6 = [22 x i8] c"FileWrite:mode ERROR!\00"
define i32 @FileWrite(i8* %0, i8* nocapture %1, i8* %2) {
%4 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %32
17: ; preds = %12, %9, %6, %3
%18 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %20, %17
%24 = tail call i32 @FileWritePermissionCheck(i8* %0)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %32
28: ; preds = %23, %20
%29 = tail call i32* @fopen(i8* %0, i8* %2)
%30 = tail call i32 @fprintf(i32* %29, i8* %1)
%31 = tail call i32 @fclose(i32* %29)
br label %32
32: ; preds = %28, %26, %15
%33 = phi i32 [ 0, %15 ], [ 0, %26 ], [ 1, %28 ]
ret i32 %33
}