#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 */

/* Variables and functions */
scalar_t__ O_CREAT;
scalar_t__ O_RDONLY;
scalar_t__ O_RDWR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char const *, scalar_t__, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcmp(char const *, char *);
int sqImageFileOpen(const char *fileName, const char *mode) {
  int fd =
      open(fileName, !strcmp(mode, "rb") ? O_RDONLY : O_RDWR + O_CREAT, 0666);
  if (fd < 0) {
    perror("sqImageFileOpen open");
    exit(errno);
  }
  return fd;
}


x86 assembly (clang, -O0):
<sqImageFileOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1184 <sqImageFileOpen+0x44>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    119c <sqImageFileOpen+0x5c>
mov    0x2e55(%rip),%rax
mov    (%rax),%rax
mov    0x2e63(%rip),%rcx
add    (%rcx),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1b6,%edx
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <sqImageFileOpen+0x95>
lea    0xe41(%rip),%rdi
call   1050 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqImageFileOpen>:
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    1166 <sqImageFileOpen+0x26>
mov    0x2e77(%rip),%rax
mov    (%rax),%rsi
jmp    117a <sqImageFileOpen+0x3a>
mov    0x2e73(%rip),%rax
mov    0x2e84(%rip),%rcx
mov    (%rcx),%rsi
add    (%rax),%rsi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1040 <open@plt>
test   %eax,%eax
js     118d <sqImageFileOpen+0x4d>
pop    %rbx
ret
lea    0xe6f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@O_RDONLY = global i64 0
@O_RDWR = global i64 0
@O_CREAT = global i64 0
@.str.1 = [21 x i8] c"sqImageFileOpen open\00"
@errno = global i32 0
define i32 @sqImageFileOpen(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = load i64, i64* @O_RDONLY
br label %16
12: ; preds = %2
%13 = load i64, i64* @O_RDWR
%14 = load i64, i64* @O_CREAT
%15 = add nsw i64 %13, %14
br label %16
16: ; preds = %12, %10
%17 = phi i64 [ %11, %10 ], [ %15, %12 ]
%18 = call i32 @open(i8* %6, i64 %17, i32 438)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %16
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@O_RDONLY = global i64 0
@O_RDWR = global i64 0
@O_CREAT = global i64 0
@.str.1 = [21 x i8] c"sqImageFileOpen open\00"
@errno = global i32 0
define i32 @sqImageFileOpen(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
%5 = load i64, i64* @O_RDONLY
%6 = load i64, i64* @O_RDWR
%7 = load i64, i64* @O_CREAT
%8 = add nsw i64 %7, %6
%9 = select i1 %4, i64 %5, i64 %8
%10 = tail call i32 @open(i8* %0, i64 %9, i32 438)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @errno
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
ret i32 %10
}