#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 /*<<< orphan*/ O_RDWR;
int O_WRONLY;
int open(char *, int, ...);
int write(int, char *, int);
int main() {
  char ch[] = "1337";
  int fd = open("./somefile", O_RDWR);
  int fd2 = open("./not_existing", O_WRONLY | O_CREAT, 0200);
  int wr = write(fd, ch, 2);
  int wr2 = write(fd2, ch, 2);
  return !(wr == 2 && wr2 == 2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xecb(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xec6(%rip),%al
mov    %al,-0x5(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
mov    0x2e8d(%rip),%rax
or     (%rax),%esi
lea    0xe9c(%rip),%rdi
mov    $0x80,%edx
mov    $0x0,%al
call   1040 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x18(%rbp)
mov    %al,-0x1d(%rbp)
jne    11c4 <main+0xa4>
cmpl   $0x2,-0x1c(%rbp)
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movb   $0x0,0xc(%rsp)
movl   $0x37333331,0x8(%rsp)
37
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebx
mov    0x2e73(%rip),%rax
mov    0x2e9c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea9(%rip),%rdi
mov    $0x80,%edx
xor    %eax,%eax
call   1040 <open@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
xor    $0x2,%ebx
xor    $0x2,%eax
xor    %ecx,%ecx
or     %ebx,%eax
setne  %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.ch = [5 x i8] c"1337\00"
@.str = [11 x i8] c"./somefile\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"./not_existing\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [5 x i8]* %2 to i8*
%8 = load i32, i32* @O_RDWR
%9 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_CREAT
%12 = or i32 %10, %11
%13 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 128)
store i32 %13, i32* %4
%14 = load i32, i32* %3
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%16 = call i32 @write(i32 %14, i8* %15, i32 2)
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%19 = call i32 @write(i32 %17, i8* %18, i32 2)
store i32 %19, i32* %6
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %0
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 2
br label %25
25: ; preds = %22, %0
%26 = phi i1 [ false, %0 ], [ %24, %22 ]
%27 = xor i1 %26, true
%28 = zext i1 %27 to i32
ret i32 %28
}

LLVM IR (-O2):
@__const.main.ch = [5 x i8] c"1337\00"
@.str = [11 x i8] c"./somefile\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"./not_existing\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 128)
%9 = call i32 @write(i32 %4, i8* %2, i32 2)
%10 = call i32 @write(i32 %8, i8* %2, i32 2)
%11 = icmp ne i32 %9, 2
%12 = icmp ne i32 %10, 2
%13 = or i1 %11, %12
%14 = zext i1 %13 to i32
ret i32 %14
}