#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISBLK(int /*<<< orphan*/);
scalar_t__ S_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ new_file();
int /*<<< orphan*/ nperror(char *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ read_file(int /*<<< orphan*/ *, char const *, int);
int stat(char const *, struct stat *);
int /*<<< orphan*/ statusbar(char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int open_file(const char *filename, int insert, int quiet) {
  int fd;
  FILE *f;
  struct stat fileinfo;
  if (filename[0] == '\0' || stat(filename, &fileinfo) == -1) {
    if (insert && !quiet) {
      statusbar(("\"%s\" not found"), filename);
      return -1;
    } else {
      statusbar(("New File"));
      new_file();
    }
  } else if (S_ISDIR(fileinfo.st_mode) || S_ISCHR(fileinfo.st_mode) ||
             S_ISBLK(fileinfo.st_mode)) {
    statusbar(S_ISDIR(fileinfo.st_mode) ? ("\"%s\" is a directory")
                                        : ("File \"%s\" is a device file"),
              filename);
    if (!insert)
      new_file();
    return -1;
  } else if ((fd = open(filename, O_RDONLY)) == -1) {
    if (!quiet)
      statusbar("%s: %s", strerror(errno), filename);
    if (!insert)
      new_file();
    return -1;
  } else {
    if (!quiet)
      statusbar(("Reading File"));
    f = fdopen(fd, "rb");
    if (f == NULL) {
      nperror("fdopen");
      close(fd);
      return -1;
    }
    read_file(f, filename, quiet);
  }
  return 1;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f8 <open_file+0x38>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
jne    1244 <open_file+0x84>
cmpl   $0x0,-0x14(%rbp)
je     122a <open_file+0x6a>
cmpl   $0x0,-0x18(%rbp)
jne    122a <open_file+0x6a>
mov    -0x10(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1080 <statusbar@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <open_file+0x1e1>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1080 <statusbar@plt>
mov    $0x0,%al
call   1060 <new_file@plt>
jmp    139a <open_file+0x1da>
mov    -0x30(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    127a <open_file+0xba>
mov    -0x30(%rbp),%edi
call   1090 <S_ISCHR@plt>
cmp    $0x0,%rax
jne    127a <open_file+0xba>
mov    -0x30(%rbp),%edi
call   10a0 <S_ISBLK@plt>
cmp    $0x0,%rax
je     12c3 <open_file+0x103>
mov    -0x30(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rcx
lea    0xda0(%rip),%rdi
lea    0xd85(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1080 <statusbar@plt>
cmpl   $0x0,-0x14(%rbp)
jne    12b7 <open_file+0xf7>
mov    $0x0,%al
call   1060 <new_file@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <open_file+0x1e1>
mov    -0x10(%rbp),%rdi
mov    0x2d1a(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    132a <open_file+0x16a>
cmpl   $0x0,-0x18(%rbp)
jne    130d <open_file+0x14d>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1080 <statusbar@plt>
cmpl   $0x0,-0x14(%rbp)
jne    131e <open_file+0x15e>
mov    $0x0,%al
call   1060 <new_file@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <open_file+0x1e1>
cmpl   $0x0,-0x18(%rbp)
jne    1342 <open_file+0x182>
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1080 <statusbar@plt>
mov    -0x1c(%rbp),%edi
lea    0xd0f(%rip),%rsi
call   10b0 <fdopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1380 <open_file+0x1c0>
lea    0xcf7(%rip),%rdi
call   10c0 <nperror@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13a1 <open_file+0x1e1>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1070 <read_file@plt>
jmp    1395 <open_file+0x1d5>
jmp    139a <open_file+0x1da>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1251 <open_file+0x91>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <stat@plt>
cmp    $0xffffffff,%eax
je     1251 <open_file+0x91>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
jne    1218 <open_file+0x58>
mov    %ebp,%edi
call   1090 <S_ISCHR@plt>
test   %rax,%rax
jne    1218 <open_file+0x58>
mov    %ebp,%edi
call   10a0 <S_ISBLK@plt>
test   %rax,%rax
je     129c <open_file+0xdc>
mov    %ebp,%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
lea    0xe03(%rip),%rax
lea    0xde8(%rip),%rdi
cmove  %rax,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <statusbar@plt>
mov    $0xffffffff,%ebx
test   %r12d,%r12d
jne    128d <open_file+0xcd>
xor    %eax,%eax
call   1060 <new_file@plt>
jmp    128d <open_file+0xcd>
test   %r12d,%r12d
je     1273 <open_file+0xb3>
test   %r14d,%r14d
jne    1273 <open_file+0xb3>
lea    0xd9e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <statusbar@plt>
mov    $0xffffffff,%ebx
jmp    128d <open_file+0xcd>
lea    0xd95(%rip),%rdi
xor    %eax,%eax
call   1080 <statusbar@plt>
xor    %eax,%eax
call   1060 <new_file@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d45(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     12ec <open_file+0x12c>
mov    %eax,%r15d
test   %r14d,%r14d
jne    12c8 <open_file+0x108>
lea    0xd8d(%rip),%rdi
xor    %eax,%eax
call   1080 <statusbar@plt>
lea    0xd8c(%rip),%rsi
mov    %r15d,%edi
call   10b0 <fdopen@plt>
test   %rax,%rax
je     131b <open_file+0x15b>
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <read_file@plt>
jmp    1288 <open_file+0xc8>
test   %r14d,%r14d
jne    123e <open_file+0x7e>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd3d(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <statusbar@plt>
jmp    123e <open_file+0x7e>
lea    0xd3c(%rip),%rdi
call   10c0 <nperror@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    $0xffffffff,%ebx
jmp    128d <open_file+0xcd>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"\22%s\22 not found\00"
@.str.1 = [9 x i8] c"New File\00"
@.str.2 = [20 x i8] c"\22%s\22 is a directory\00"
@.str.3 = [27 x i8] c"File \22%s\22 is a device file\00"
@O_RDONLY = global i32 0
@.str.4 = [7 x i8] c"%s: %s\00"
@errno = global i32 0
@.str.5 = [13 x i8] c"Reading File\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [7 x i8] c"fdopen\00"
define i32 @open_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.stat
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32 @stat(i8* %17, %struct.stat* %10)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %33
20: ; preds = %16, %3
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 -1, i32* %4
br label %103
29: ; preds = %23, %20
%30 = call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 (...) @new_file()
br label %32
32: ; preds = %29
br label %102
33: ; preds = %16
%34 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i64 @S_ISDIR(i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %48, label %38
38: ; preds = %33
%39 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @S_ISCHR(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i64 @S_ISBLK(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %62
48: ; preds = %43, %38, %33
%49 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i64 @S_ISDIR(i32 %50)
%52 = icmp ne i64 %51, 0
%53 = zext i1 %52 to i64
%54 = select i1 %52, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0)
%55 = load i8*, i8** %5
%56 = call i32 (i8*, ...) @statusbar(i8* %54, i8* %55)
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %48
%60 = call i32 (...) @new_file()
br label %61
61: ; preds = %59, %48
store i32 -1, i32* %4
br label %103
62: ; preds = %43
%63 = load i8*, i8** %5
%64 = load i32, i32* @O_RDONLY
%65 = call i32 @open(i8* %63, i32 %64)
store i32 %65, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %81
67: ; preds = %62
%68 = load i32, i32* %7
%69 = icmp ne i32 %68, 0
br i1 %69, label %75, label %70
70: ; preds = %67
%71 = load i32, i32* @errno
%72 = call i32 @strerror(i32 %71)
%73 = load i8*, i8** %5
%74 = call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %72, i8* %73)
br label %75
75: ; preds = %70, %67
%76 = load i32, i32* %6
%77 = icmp ne i32 %76, 0
br i1 %77, label %80, label %78
78: ; preds = %75
%79 = call i32 (...) @new_file()
br label %80
80: ; preds = %78, %75
store i32 -1, i32* %4
br label %103
81: ; preds = %62
%82 = load i32, i32* %7
%83 = icmp ne i32 %82, 0
br i1 %83, label %86, label %84
84: ; preds = %81
%85 = call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %86
86: ; preds = %84, %81
%87 = load i32, i32* %8
%88 = call i32* @fdopen(i32 %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %88, i32** %9
%89 = load i32*, i32** %9
%90 = icmp eq i32* %89, null
br i1 %90, label %91, label %95
91: ; preds = %86
%92 = call i32 @nperror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%93 = load i32, i32* %8
%94 = call i32 @close(i32 %93)
store i32 -1, i32* %4
br label %103
95: ; preds = %86
%96 = load i32*, i32** %9
%97 = load i8*, i8** %5
%98 = load i32, i32* %7
%99 = call i32 @read_file(i32* %96, i8* %97, i32 %98)
br label %100
100: ; preds = %95
br label %101
101: ; preds = %100
br label %102
102: ; preds = %101, %32
store i32 1, i32* %4
br label %103
103: ; preds = %102, %91, %80, %61, %26
%104 = load i32, i32* %4
ret i32 %104
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"\22%s\22 not found\00"
@.str.1 = [9 x i8] c"New File\00"
@.str.2 = [20 x i8] c"\22%s\22 is a directory\00"
@.str.3 = [27 x i8] c"File \22%s\22 is a device file\00"
@O_RDONLY = global i32 0
@.str.4 = [7 x i8] c"%s: %s\00"
@errno = global i32 0
@.str.5 = [13 x i8] c"Reading File\00"
@.str.6 = [3 x i8] c"rb\00"
@.str.7 = [7 x i8] c"fdopen\00"
define i32 @open_file(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i32 @stat(i8* %0, %struct.stat* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %20
11: ; preds = %8, %3
%12 = icmp eq i32 %1, 0
%13 = icmp ne i32 %2, 0
%14 = or i1 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %64
17: ; preds = %11
%18 = tail call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 (...) @new_file()
br label %64
20: ; preds = %8
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i64 @S_ISDIR(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = tail call i64 @S_ISCHR(i32 %22)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = tail call i64 @S_ISBLK(i32 %22)
%30 = icmp eq i64 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %28, %25, %20
%32 = tail call i64 @S_ISDIR(i32 %22)
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0)
%35 = tail call i32 (i8*, ...) @statusbar(i8* %34, i8* %0)
%36 = icmp eq i32 %1, 0
br i1 %36, label %37, label %64
37: ; preds = %31
%38 = tail call i32 (...) @new_file()
br label %64
39: ; preds = %28
%40 = load i32, i32* @O_RDONLY
%41 = tail call i32 @open(i8* %0, i32 %40)
%42 = icmp eq i32 %41, -1
%43 = icmp eq i32 %2, 0
br i1 %42, label %44, label %53
44: ; preds = %39
br i1 %43, label %45, label %49
45: ; preds = %44
%46 = load i32, i32* @errno
%47 = tail call i32 @strerror(i32 %46)
%48 = tail call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %0)
br label %49
49: ; preds = %45, %44
%50 = icmp eq i32 %1, 0
br i1 %50, label %51, label %64
51: ; preds = %49
%52 = tail call i32 (...) @new_file()
br label %64
53: ; preds = %39
br i1 %43, label %54, label %56
54: ; preds = %53
%55 = tail call i32 (i8*, ...) @statusbar(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %53
%57 = tail call i32* @fdopen(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%58 = icmp eq i32* %57, null
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = tail call i32 @nperror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%61 = tail call i32 @close(i32 %41)
br label %64
62: ; preds = %56
%63 = tail call i32 @read_file(i32* %57, i8* %0, i32 %2)
br label %64
64: ; preds = %17, %62, %49, %51, %31, %37, %59, %15
%65 = phi i32 [ -1, %15 ], [ -1, %59 ], [ -1, %37 ], [ -1, %31 ], [ -1, %51 ], [ -1, %49 ], [ 1, %62 ], [ 1, %17 ]
ret i32 %65
}