#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*/ printf(char *);
int /*<<< orphan*/ safeGetString(char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int checkOverwrite(char *fileName) {
  char temp[255];
  FILE *file = fopen(fileName, "r");
  if (file) {
    fclose(file);
    do {
      printf("File already exist, overwrite(Y/N): ");
      safeGetString(temp, 255);
      if (!strcmp(temp, "Y") || !strcmp(temp, "y"))
        return 0;
      else if ((!strcmp(temp, "N") || !strcmp(temp, "n")))
        return 1;
    } while (1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkOverwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     1253 <checkOverwrite+0x103>
mov    -0x118(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    $0xff,%esi
call   1040 <safeGetString@plt>
lea    -0x110(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11e5 <checkOverwrite+0x95>
lea    -0x110(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11f1 <checkOverwrite+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    125a <checkOverwrite+0x10a>
lea    -0x110(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     1229 <checkOverwrite+0xd9>
lea    -0x110(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1235 <checkOverwrite+0xe5>
movl   $0x1,-0x4(%rbp)
jmp    125a <checkOverwrite+0x10a>
jmp    123a <checkOverwrite+0xea>
jmp    123f <checkOverwrite+0xef>
mov    $0x1,%al
test   $0x1,%al
jne    1190 <checkOverwrite+0x40>
jmp    124e <checkOverwrite+0xfe>
jmp    1253 <checkOverwrite+0x103>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkOverwrite>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11c4 <checkOverwrite+0x84>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xe94(%rip),%rbx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    $0xff,%esi
call   1040 <safeGetString@plt>
movzwl (%rsp),%eax
cmp    $0x6d,%ax
jg     11b0 <checkOverwrite+0x70>
cmp    $0x4e,%ax
je     11be <checkOverwrite+0x7e>
cmp    $0x59,%ax
jne    1180 <checkOverwrite+0x40>
jmp    11c4 <checkOverwrite+0x84>
nopl   (%rax)
cmp    $0x6e,%ax
je     11be <checkOverwrite+0x7e>
cmp    $0x79,%ax
jne    1180 <checkOverwrite+0x40>
jmp    11c4 <checkOverwrite+0x84>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"File already exist, overwrite(Y/N): \00"
@.str.2 = [2 x i8] c"Y\00"
@.str.3 = [2 x i8] c"y\00"
@.str.4 = [2 x i8] c"N\00"
@.str.5 = [2 x i8] c"n\00"
define i32 @checkOverwrite(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [255 x i8]
%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** %5
%8 = load i32*, i32** %5
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %38
10: ; preds = %1
%11 = load i32*, i32** %5
%12 = call i32 @fclose(i32* %11)
br label %13
13: ; preds = %36, %10
%14 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%16 = call i32 @safeGetString(i8* %15, i32 255)
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %13
%21 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20, %13
store i32 0, i32* %2
br label %39
25: ; preds = %20
%26 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %29, %25
store i32 1, i32* %2
br label %39
34: ; preds = %29
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br i1 true, label %13, label %37
37: ; preds = %36
br label %38
38: ; preds = %37, %1
store i32 0, i32* %2
br label %39
39: ; preds = %38, %33, %24
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [37 x i8] c"File already exist, overwrite(Y/N): \00"
define i32 @checkOverwrite(i8* nocapture %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %14, label %6
6: ; preds = %1
%7 = tail call i32 @fclose(i32* %4)
%8 = bitcast [255 x i8]* %2 to i16*
br label %9
9: ; preds = %9, %6
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @safeGetString(i8* %3, i32 255)
%12 = load i16, i16* %8
switch i16 %12, label %9 [
i16 121, label %13
i16 89, label %13
i16 110, label %14
i16 78, label %14
]
13: ; preds = %9, %9
br label %14
14: ; preds = %9, %9, %13, %1
%15 = phi i32 [ 0, %1 ], [ 0, %13 ], [ 1, %9 ], [ 1, %9 ]
ret i32 %15
}