#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 /*<<< orphan*/ F_GETFL;
int O_CREAT;
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ assert(int);
int fcntl(int, int /*<<< orphan*/);
int open(char *, int);
int main(void) {
  int fd;
  int flags;
  fd = open("test_open.c", O_RDONLY | O_CREAT | O_NONBLOCK);
  flags = fcntl(fd, F_GETFL);
  assert(O_NONBLOCK == (flags & O_NONBLOCK));
  assert(O_CREAT == (flags & O_CREAT));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2ea9(%rip),%rax
or     (%rax),%esi
mov    0x2e88(%rip),%rax
or     (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
mov    0x2e50(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
mov    0x2e44(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    0x2eb5(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
mov    0x2e91(%rip),%r15
or     (%r15),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    0x2e63(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1030 <fcntl@plt>
mov    %eax,%ebx
not    %ebx
xor    %edi,%edi
mov    (%r15),%eax
and    %ebx,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
and    (%r14),%ebx
sete   %dil
call   1040 <assert@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"test_open.c\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_NONBLOCK = global i32 0
@F_GETFL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = load i32, i32* @O_CREAT
%6 = or i32 %4, %5
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* @F_GETFL
%12 = call i32 @fcntl(i32 %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* @O_NONBLOCK
%14 = load i32, i32* %3
%15 = load i32, i32* @O_NONBLOCK
%16 = and i32 %14, %15
%17 = icmp eq i32 %13, %16
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* %3
%22 = load i32, i32* @O_CREAT
%23 = and i32 %21, %22
%24 = icmp eq i32 %20, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"test_open.c\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_NONBLOCK = global i32 0
@F_GETFL = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = load i32, i32* @O_CREAT
%3 = or i32 %2, %1
%4 = load i32, i32* @O_NONBLOCK
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @F_GETFL
%8 = tail call i32 @fcntl(i32 %6, i32 %7)
%9 = load i32, i32* @O_NONBLOCK
%10 = and i32 %9, %8
%11 = icmp eq i32 %9, %10
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = load i32, i32* @O_CREAT
%15 = and i32 %14, %8
%16 = icmp eq i32 %14, %15
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
ret i32 0
}