#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*/ Error_write(int, char *, int, char *, ...);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ strcmp(char *, char *);
FILE *FileUtil_open(char *fname, char *stat, char *routine) {
  FILE *fp;
  if (fname == NULL || stat == NULL || routine == NULL) {
    Error_write(11, "FileUtil_open", 2, "one or more of fname,stat or routine");
    return NULL;
  }
  if (fname[0] == '\0' || stat[0] == '\0') {
    Error_write(20, "FileUtil_open", 2, "one or more of fname or stat");
    return NULL;
  }
  if (!strcmp(fname, "stdout")) {
    fp = stdout;
  } else if (!strcmp(fname, "stderr")) {
    fp = stderr;
  } else if ((fp = fopen(fname, stat)) == NULL) {
    Error_write(1, routine, 2, "File %s. Mode %s", fname, stat);
    return NULL;
  }
  return fp;
}


x86 assembly (clang, -O0):
<FileUtil_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <FileUtil_open+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1165 <FileUtil_open+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1191 <FileUtil_open+0x61>
mov    $0xb,%edi
lea    0xe8f(%rip),%rsi
mov    $0x2,%edx
lea    0xe91(%rip),%rcx
mov    $0x0,%al
call   1030 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    1293 <FileUtil_open+0x163>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b1 <FileUtil_open+0x81>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11dd <FileUtil_open+0xad>
mov    $0x14,%edi
lea    0xe43(%rip),%rsi
mov    $0x2,%edx
lea    0xe6a(%rip),%rcx
mov    $0x0,%al
call   1030 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    1293 <FileUtil_open+0x163>
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1209 <FileUtil_open+0xd9>
mov    0x2ddb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    128b <FileUtil_open+0x15b>
mov    -0x10(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1235 <FileUtil_open+0x105>
mov    0x2db7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1286 <FileUtil_open+0x156>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1281 <FileUtil_open+0x151>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
mov    $0x1,%edi
mov    $0x2,%edx
lea    0xdf1(%rip),%rcx
mov    $0x0,%al
call   1030 <Error_write@plt>
movq   $0x0,-0x8(%rbp)
jmp    1293 <FileUtil_open+0x163>
jmp    1286 <FileUtil_open+0x156>
jmp    128b <FileUtil_open+0x15b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FileUtil_open>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ce <FileUtil_open+0x9e>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ce <FileUtil_open+0x9e>
mov    %rdx,%r15
test   %rdx,%rdx
je     11ce <FileUtil_open+0x9e>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11e6 <FileUtil_open+0xb6>
cmpb   $0x0,(%r14)
je     11e6 <FileUtil_open+0xb6>
lea    0xee2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1217 <FileUtil_open+0xe7>
lea    0xed2(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1223 <FileUtil_open+0xf3>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1208 <FileUtil_open+0xd8>
lea    0xeaf(%rip),%rcx
xor    %r12d,%r12d
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x2,%edx
mov    %rbx,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1030 <Error_write@plt>
jmp    1208 <FileUtil_open+0xd8>
lea    0xe2b(%rip),%rsi
lea    0xe32(%rip),%rcx
xor    %r12d,%r12d
mov    $0xb,%edi
jmp    11fc <FileUtil_open+0xcc>
lea    0xe13(%rip),%rsi
lea    0xe3f(%rip),%rcx
xor    %r12d,%r12d
mov    $0x14,%edi
mov    $0x2,%edx
xor    %eax,%eax
call   1030 <Error_write@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%r12
jmp    1208 <FileUtil_open+0xd8>
mov    0x2db6(%rip),%rax
mov    (%rax),%r12
jmp    1208 <FileUtil_open+0xd8>

LLVM IR (-O0):
@.str = [14 x i8] c"FileUtil_open\00"
@.str.1 = [37 x i8] c"one or more of fname,stat or routine\00"
@.str.2 = [29 x i8] c"one or more of fname or stat\00"
@.str.3 = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.4 = [7 x i8] c"stderr\00"
@stderr = global i32* null
@.str.5 = [17 x i8] c"File %s. Mode %s\00"
define i32* @FileUtil_open(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** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14, %11, %3
%18 = call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %4
br label %59
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25, %19
%32 = call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32* null, i32** %4
br label %59
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = load i32*, i32** @stdout
store i32* %38, i32** %8
br label %57
39: ; preds = %33
%40 = load i8*, i8** %5
%41 = call i32 @strcmp(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp ne i32 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = load i32*, i32** @stderr
store i32* %44, i32** %8
br label %56
45: ; preds = %39
%46 = load i8*, i8** %5
%47 = load i8*, i8** %6
%48 = call i32* @fopen(i8* %46, i8* %47)
store i32* %48, i32** %8
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i8*, i8** %7
%52 = load i8*, i8** %5
%53 = load i8*, i8** %6
%54 = call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 1, i8* %51, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %52, i8* %53)
store i32* null, i32** %4
br label %59
55: ; preds = %45
br label %56
56: ; preds = %55, %43
br label %57
57: ; preds = %56, %37
%58 = load i32*, i32** %8
store i32* %58, i32** %4
br label %59
59: ; preds = %57, %50, %31, %17
%60 = load i32*, i32** %4
ret i32* %60
}

LLVM IR (-O2):
@.str = [14 x i8] c"FileUtil_open\00"
@.str.1 = [37 x i8] c"one or more of fname,stat or routine\00"
@.str.2 = [29 x i8] c"one or more of fname or stat\00"
@.str.3 = [7 x i8] c"stdout\00"
@stdout = global i32* null
@.str.4 = [7 x i8] c"stderr\00"
@stderr = global i32* null
@.str.5 = [17 x i8] c"File %s. Mode %s\00"
define i32* @FileUtil_open(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %34
11: ; preds = %3
%12 = load i8, i8* %0
%13 = icmp eq i8 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %11
%18 = tail call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %34
19: ; preds = %14
%20 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32*, i32** @stdout
br label %34
24: ; preds = %19
%25 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32*, i32** @stderr
br label %34
29: ; preds = %24
%30 = tail call i32* @fopen(i8* %0, i8* %1)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 (i32, i8*, i32, i8*, ...) @Error_write(i32 1, i8* %2, i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1)
br label %34
34: ; preds = %22, %29, %27, %32, %17, %9
%35 = phi i32* [ null, %9 ], [ null, %17 ], [ null, %32 ], [ %30, %29 ], [ %28, %27 ], [ %23, %22 ]
ret i32* %35
}