#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*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char const *, char *);
int get_fileHandle(const char *input_filename, const char *output_filename,
                   FILE **pfinput, FILE **pfoutput) {
  char stdinmark[] = "stdin";
  char stdoutmark[] = "stdout";
  if (!strcmp(input_filename, stdinmark)) {
    fprintf(stderr, "Using stdin for input\n");
    *pfinput = stdin;
  } else {
    *pfinput = fopen(input_filename, "rb");
  }
  if (!strcmp(output_filename, stdoutmark)) {
    fprintf(stderr, "Using stdout for output\n");
    *pfoutput = stdout;
  } else {
    *pfoutput = fopen(output_filename, "wb");
  }
  if (*pfinput == 0) {
    fprintf(stderr, "Pb opening %s\n", input_filename);
    return 2;
  }
  if (*pfoutput == 0) {
    fprintf(stderr, "Pb opening %s\n", output_filename);
    return 3;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_fileHandle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0xeb2(%rip),%eax
mov    %eax,-0x2e(%rbp)
mov    0xeac(%rip),%ax
mov    %ax,-0x2a(%rbp)
mov    0xea4(%rip),%eax
mov    %eax,-0x35(%rbp)
mov    0xe9e(%rip),%ax
mov    %ax,-0x31(%rbp)
mov    0xe96(%rip),%al
mov    %al,-0x2f(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x2e(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11bc <get_fileHandle+0x8c>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    11d6 <get_fileHandle+0xa6>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x35(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1219 <get_fileHandle+0xe9>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1233 <get_fileHandle+0x103>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1268 <get_fileHandle+0x138>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12a4 <get_fileHandle+0x174>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    129d <get_fileHandle+0x16d>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    12a4 <get_fileHandle+0x174>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fileHandle>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb5(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1165 <get_fileHandle+0x35>
lea    0xec9(%rip),%rsi
mov    %r15,%rdi
call   1050 <fopen@plt>
jmp    1186 <get_fileHandle+0x56>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11ad <get_fileHandle+0x7d>
lea    0xe9d(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
jmp    11ce <get_fileHandle+0x9e>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe6a(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%r12)
cmpq   $0x0,(%rbx)
je     11e9 <get_fileHandle+0xb9>
xor    %ebx,%ebx
test   %rax,%rax
jne    1208 <get_fileHandle+0xd8>
mov    $0x3,%ebx
mov    %r14,%r15
jmp    11ee <get_fileHandle+0xbe>
mov    $0x2,%ebx
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.get_fileHandle.stdinmark = [6 x i8] c"stdin\00"
@__const.get_fileHandle.stdoutmark = [7 x i8] c"stdout\00"
@stderr = global i32 0
@.str = [23 x i8] c"Using stdin for input\0A\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"Using stdout for output\0A\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [15 x i8] c"Pb opening %s\0A\00"
define i32 @get_fileHandle(i8* %0, i8* %1, i32** %2, i32** %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32**
%9 = alloca i32**
%10 = alloca [6 x i8]
%11 = alloca [7 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32** %2, i32*** %8
store i32** %3, i32*** %9
%12 = bitcast [6 x i8]* %10 to i8*
%13 = bitcast [7 x i8]* %11 to i8*
%14 = load i8*, i8** %6
%15 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%16 = call i32 @strcmp(i8* %14, i8* %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %4
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = load i32*, i32** @stdin
%22 = load i32**, i32*** %8
store i32* %21, i32** %22
br label %27
23: ; preds = %4
%24 = load i8*, i8** %6
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32**, i32*** %8
store i32* %25, i32** %26
br label %27
27: ; preds = %23, %18
%28 = load i8*, i8** %7
%29 = getelementptr inbounds [7 x i8], [7 x i8]* %11, i64 0, i64 0
%30 = call i32 @strcmp(i8* %28, i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32*, i32** @stdout
%36 = load i32**, i32*** %9
store i32* %35, i32** %36
br label %41
37: ; preds = %27
%38 = load i8*, i8** %7
%39 = call i32* @fopen(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32**, i32*** %9
store i32* %39, i32** %40
br label %41
41: ; preds = %37, %32
%42 = load i32**, i32*** %8
%43 = load i32*, i32** %42
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %6
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %47)
store i32 2, i32* %5
br label %58
49: ; preds = %41
%50 = load i32**, i32*** %9
%51 = load i32*, i32** %50
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %7
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %55)
store i32 3, i32* %5
br label %58
57: ; preds = %49
store i32 0, i32* %5
br label %58
58: ; preds = %57, %53, %45
%59 = load i32, i32* %5
ret i32 %59
}

LLVM IR (-O2):
@__const.get_fileHandle.stdinmark = [6 x i8] c"stdin\00"
@__const.get_fileHandle.stdoutmark = [7 x i8] c"stdout\00"
@stderr = global i32 0
@.str = [23 x i8] c"Using stdin for input\0A\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [25 x i8] c"Using stdout for output\0A\00"
@stdout = global i32* null
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [15 x i8] c"Pb opening %s\0A\00"
define i32 @get_fileHandle(i8* %0, i8* %1, i32** nocapture %2, i32** nocapture %3) {
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @__const.get_fileHandle.stdinmark, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = load i32*, i32** @stdin
br label %13
11: ; preds = %4
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = phi i32* [ %10, %7 ], [ %12, %11 ]
store i32* %14, i32** %2
%15 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @__const.get_fileHandle.stdoutmark, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** @stdout
br label %23
21: ; preds = %13
%22 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = phi i32* [ %20, %17 ], [ %22, %21 ]
store i32* %24, i32** %3
%25 = load i32*, i32** %2
%26 = icmp eq i32* %25, null
br i1 %26, label %29, label %27
27: ; preds = %23
%28 = icmp eq i32* %24, null
br i1 %28, label %29, label %34
29: ; preds = %27, %23
%30 = phi i8* [ %0, %23 ], [ %1, %27 ]
%31 = phi i32 [ 2, %23 ], [ 3, %27 ]
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %34
34: ; preds = %29, %27
%35 = phi i32 [ 0, %27 ], [ %31, %29 ]
ret i32 %35
}