#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*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
FILE *erdOpenFileOrRetry(char *FileName, char *How) {
  FILE *temp;
  char F[300];
  sprintf(F, "%s", FileName);
  while (!(temp = fopen(F, How))) {
    printf("\n\nI'm terribly sorry.  I can't open file \"%s\"\n", F);
    printf("\nPlease enter a new file name, or x or X to quit\n->");
    scanf("%s", F);
    if ((strcmp(F, "X") == 0) || (strcmp(F, "x") == 0))
      exit(1);
  }
  return (temp);
}


x86 assembly (clang, -O0):
<erdOpenFileOrRetry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe7b(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x150(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b4 <erdOpenFileOrRetry+0x54>
jmp    1233 <erdOpenFileOrRetry+0xd3>
lea    -0x150(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x150(%rbp),%rsi
lea    0xe1b(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x150(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1224 <erdOpenFileOrRetry+0xc4>
lea    -0x150(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    122e <erdOpenFileOrRetry+0xce>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    118a <erdOpenFileOrRetry+0x2a>
mov    -0x18(%rbp),%rax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<erdOpenFileOrRetry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xea9(%rip),%r12
lea    0xe70(%rip),%r13
lea    0xecf(%rip),%rbp
lea    0xeca(%rip),%r15
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    1200 <erdOpenFileOrRetry+0xa0>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11f6 <erdOpenFileOrRetry+0x96>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a0 <erdOpenFileOrRetry+0x40>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [47 x i8] c"\0A\0AI'm terribly sorry. I can't open file \22%s\22\0A\00"
@.str.2 = [52 x i8] c"\0APlease enter a new file name, or x or X to quit\0A->\00"
@.str.3 = [2 x i8] c"X\00"
@.str.4 = [2 x i8] c"x\00"
define i32* @erdOpenFileOrRetry(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [300 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %31, %2
%11 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %11, i8* %12)
store i32* %13, i32** %5
%14 = icmp ne i32* %13, null
%15 = xor i1 %14, true
br i1 %15, label %16, label %32
16: ; preds = %10
%17 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %16
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %6, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25, %16
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %25
br label %10
32: ; preds = %10
%33 = load i32*, i32** %5
ret i32* %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [47 x i8] c"\0A\0AI'm terribly sorry. I can't open file \22%s\22\0A\00"
@.str.2 = [52 x i8] c"\0APlease enter a new file name, or x or X to quit\0A->\00"
@.str.3 = [2 x i8] c"X\00"
@.str.4 = [2 x i8] c"x\00"
define noalias i32* @erdOpenFileOrRetry(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [300 x i8]
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%5 = call i8* @strcpy(i8* %4, i8* dereferenceable(1) %0)
br label %6
6: ; preds = %15, %2
%7 = call i32* @fopen(i8* %4, i8* %1)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %6
18: ; preds = %15, %9
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %6
ret i32* %7
}