#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 */
int O_CREAT;
int O_EXCL;
int O_RDWR;
int S_IRUSR;
int S_IWUSR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int open(char const *, int, int);
int /*<<< orphan*/ perror(char *);
int open_or_exit(const char *file_name) {
  int result = -1;
  errno = 0;
  result = open(file_name, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
  if (result < 0) {
    perror("Can't open");
    exit(3);
  }
  return (result);
}


x86 assembly (clang, -O0):
<open_or_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2e76(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    0x2e93(%rip),%rax
or     (%rax),%esi
mov    0x2e5a(%rip),%rax
or     (%rax),%esi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    0x2e58(%rip),%rax
or     (%rax),%edx
call   1030 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11aa <open_or_exit+0x7a>
lea    0xe65(%rip),%rdi
call   1040 <perror@plt>
mov    $0x3,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_or_exit>:
push   %rax
mov    0x2e88(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e9a(%rip),%rax
mov    0x2eab(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
mov    0x2e57(%rip),%rax
mov    0x2e70(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1030 <open@plt>
test   %eax,%eax
js     1177 <open_or_exit+0x47>
pop    %rcx
ret
lea    0xe82(%rip),%rdi
call   1040 <perror@plt>
mov    $0x3,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [11 x i8] c"Can't open\00"
define i32 @open_or_exit(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = load i32, i32* @O_EXCL
%9 = or i32 %7, %8
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = call i32 @open(i8* %4, i32 %9, i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 3)
unreachable
19: ; preds = %1
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@errno = global i64 0
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str = [11 x i8] c"Can't open\00"
define i32 @open_or_exit(i8* nocapture %0) {
store i64 0, i64* @errno
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_EXCL
%6 = or i32 %4, %5
%7 = load i32, i32* @S_IRUSR
%8 = load i32, i32* @S_IWUSR
%9 = or i32 %8, %7
%10 = tail call i32 @open(i8* %0, i32 %6, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 3)
unreachable
15: ; preds = %1
ret i32 %10
}