#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_RDONLY;
int O_RDWR;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int generic_open_read_write(char *, int, int);
int /*<<< orphan*/ stderr;
int test_open_modes(char *filename) {
  int ret = -1;
  int result = 0;
  ret = generic_open_read_write(filename, O_CREAT | O_WRONLY, 0666);
  if (ret != 0) {
    fprintf(stderr, "flag O_CREAT|O_WRONLY failed: \n");
    result |= ret;
  }
  ret = generic_open_read_write(filename, O_CREAT | O_RDWR, 0666);
  if (ret != 0) {
    fprintf(stderr, "flag O_CREAT|O_RDWR failed\n");
    result |= ret;
  }
  ret = generic_open_read_write(filename, O_CREAT | O_RDONLY, 0666);
  if (ret != 0) {
    fprintf(stderr, "flag O_CREAT|O_RDONLY failed\n");
    result |= ret;
  }
  ret = creat(filename, 0644);
  close(ret);
  ret = generic_open_read_write(filename, O_WRONLY, 0);
  if (ret != 0) {
    fprintf(stderr, "flag O_WRONLY failed\n");
    result |= ret;
  }
  ret = creat(filename, 0644);
  close(ret);
  ret = generic_open_read_write(filename, O_RDWR, 0);
  if (0 != ret) {
    fprintf(stderr, "flag O_RDWR failed\n");
    result |= ret;
  }
  ret = creat(filename, 0644);
  close(ret);
  ret = generic_open_read_write(filename, O_RDONLY, 0);
  if (0 != ret) {
    fprintf(stderr, "flag O_RDONLY failed\n");
    result |= ret;
  }
  ret = creat(filename, 0644);
  close(ret);
  ret = generic_open_read_write(filename, O_TRUNC | O_WRONLY, 0);
  if (0 != ret) {
    fprintf(stderr, "flag O_TRUNC|O_WRONLY failed\n");
    result |= ret;
  }
  ret = generic_open_read_write(filename, O_CREAT | O_RDWR | O_SYNC, 0666);
  if (0 != ret) {
    fprintf(stderr, "flag O_CREAT|O_RDWR|O_SYNC failed\n");
    result |= ret;
  }
  ret = creat(filename, 0644);
  close(ret);
  ret = generic_open_read_write(filename, O_CREAT | O_EXCL, 0666);
  if (0 != ret) {
    fprintf(stderr, "flag O_CREAT|O_EXCL failed\n");
    result |= ret;
  }
  return result;
}


x86 assembly (clang, -O0):
<test_open_modes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2e32(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a5 <test_open_modes+0x65>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e1f(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11f0 <test_open_modes+0xb0>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
lea    0xe3e(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    0x2dc4(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     123b <test_open_modes+0xfb>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1293 <test_open_modes+0x153>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     12ec <test_open_modes+0x1ac>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2cb8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     1345 <test_open_modes+0x205>
mov    0x2c8a(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
mov    0x2c2e(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     13a7 <test_open_modes+0x267>
mov    0x2c28(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2c46(%rip),%rax
mov    (%rax),%esi
mov    0x2c1d(%rip),%rax
or     (%rax),%esi
mov    0x2c0c(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     13fc <test_open_modes+0x2bc>
mov    0x2bd3(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    0x2bd8(%rip),%rax
mov    (%rax),%esi
mov    0x2b87(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
je     1461 <test_open_modes+0x321>
mov    0x2b6e(%rip),%rax
mov    (%rax),%edi
lea    0xc88(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0xc(%rbp),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_open_modes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea3(%rip),%r15
mov    0x2e44(%rip),%r13
mov    0x0(%r13),%esi
or     (%r15),%esi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
mov    %eax,%r14d
test   %eax,%eax
je     1189 <test_open_modes+0x49>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     11c0 <test_open_modes+0x80>
mov    %eax,%ebp
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    0x2e01(%rip),%r12
mov    (%r12),%esi
or     (%r15),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     11f9 <test_open_modes+0xb9>
mov    %eax,%ebp
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     1239 <test_open_modes+0xf9>
mov    %eax,%ebp
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     127e <test_open_modes+0x13e>
mov    %eax,%ebp
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    (%r12),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     12be <test_open_modes+0x17e>
mov    %eax,%ebp
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    0x2d17(%rip),%rax
mov    0x0(%r13),%esi
or     (%rax),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     1307 <test_open_modes+0x1c7>
mov    %eax,%ebp
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    0x2cca(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    0x2cb6(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     1347 <test_open_modes+0x207>
mov    %eax,%ebp
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebp,%r14d
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1060 <creat@plt>
mov    %eax,%edi
call   1040 <close@plt>
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1030 <generic_open_read_write@plt>
test   %eax,%eax
je     1392 <test_open_modes+0x252>
mov    %eax,%ebx
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
call   1050 <fprintf@plt>
or     %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"flag O_CREAT|O_WRONLY failed: \0A\00"
@O_RDWR = global i32 0
@.str.1 = [28 x i8] c"flag O_CREAT|O_RDWR failed\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"flag O_CREAT|O_RDONLY failed\0A\00"
@.str.3 = [22 x i8] c"flag O_WRONLY failed\0A\00"
@.str.4 = [20 x i8] c"flag O_RDWR failed\0A\00"
@.str.5 = [22 x i8] c"flag O_RDONLY failed\0A\00"
@O_TRUNC = global i32 0
@.str.6 = [30 x i8] c"flag O_TRUNC|O_WRONLY failed\0A\00"
@O_SYNC = global i32 0
@.str.7 = [35 x i8] c"flag O_CREAT|O_RDWR|O_SYNC failed\0A\00"
@O_EXCL = global i32 0
@.str.8 = [28 x i8] c"flag O_CREAT|O_EXCL failed\0A\00"
define i32 @test_open_modes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
store i32 0, i32* %4
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %6, %7
%9 = call i32 @generic_open_read_write(i8* %5, i32 %8, i32 438)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = or i32 %16, %15
store i32 %17, i32* %4
br label %18
18: ; preds = %12, %1
%19 = load i8*, i8** %2
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_RDWR
%22 = or i32 %20, %21
%23 = call i32 @generic_open_read_write(i8* %19, i32 %22, i32 438)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = or i32 %30, %29
store i32 %31, i32* %4
br label %32
32: ; preds = %26, %18
%33 = load i8*, i8** %2
%34 = load i32, i32* @O_CREAT
%35 = load i32, i32* @O_RDONLY
%36 = or i32 %34, %35
%37 = call i32 @generic_open_read_write(i8* %33, i32 %36, i32 438)
store i32 %37, i32* %3
%38 = load i32, i32* %3
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = or i32 %44, %43
store i32 %45, i32* %4
br label %46
46: ; preds = %40, %32
%47 = load i8*, i8** %2
%48 = call i32 @creat(i8* %47, i32 420)
store i32 %48, i32* %3
%49 = load i32, i32* %3
%50 = call i32 @close(i32 %49)
%51 = load i8*, i8** %2
%52 = load i32, i32* @O_WRONLY
%53 = call i32 @generic_open_read_write(i8* %51, i32 %52, i32 0)
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %46
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = or i32 %60, %59
store i32 %61, i32* %4
br label %62
62: ; preds = %56, %46
%63 = load i8*, i8** %2
%64 = call i32 @creat(i8* %63, i32 420)
store i32 %64, i32* %3
%65 = load i32, i32* %3
%66 = call i32 @close(i32 %65)
%67 = load i8*, i8** %2
%68 = load i32, i32* @O_RDWR
%69 = call i32 @generic_open_read_write(i8* %67, i32 %68, i32 0)
store i32 %69, i32* %3
%70 = load i32, i32* %3
%71 = icmp ne i32 0, %70
br i1 %71, label %72, label %78
72: ; preds = %62
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32, i32* %3
%76 = load i32, i32* %4
%77 = or i32 %76, %75
store i32 %77, i32* %4
br label %78
78: ; preds = %72, %62
%79 = load i8*, i8** %2
%80 = call i32 @creat(i8* %79, i32 420)
store i32 %80, i32* %3
%81 = load i32, i32* %3
%82 = call i32 @close(i32 %81)
%83 = load i8*, i8** %2
%84 = load i32, i32* @O_RDONLY
%85 = call i32 @generic_open_read_write(i8* %83, i32 %84, i32 0)
store i32 %85, i32* %3
%86 = load i32, i32* %3
%87 = icmp ne i32 0, %86
br i1 %87, label %88, label %94
88: ; preds = %78
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* %3
%92 = load i32, i32* %4
%93 = or i32 %92, %91
store i32 %93, i32* %4
br label %94
94: ; preds = %88, %78
%95 = load i8*, i8** %2
%96 = call i32 @creat(i8* %95, i32 420)
store i32 %96, i32* %3
%97 = load i32, i32* %3
%98 = call i32 @close(i32 %97)
%99 = load i8*, i8** %2
%100 = load i32, i32* @O_TRUNC
%101 = load i32, i32* @O_WRONLY
%102 = or i32 %100, %101
%103 = call i32 @generic_open_read_write(i8* %99, i32 %102, i32 0)
store i32 %103, i32* %3
%104 = load i32, i32* %3
%105 = icmp ne i32 0, %104
br i1 %105, label %106, label %112
106: ; preds = %94
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%109 = load i32, i32* %3
%110 = load i32, i32* %4
%111 = or i32 %110, %109
store i32 %111, i32* %4
br label %112
112: ; preds = %106, %94
%113 = load i8*, i8** %2
%114 = load i32, i32* @O_CREAT
%115 = load i32, i32* @O_RDWR
%116 = or i32 %114, %115
%117 = load i32, i32* @O_SYNC
%118 = or i32 %116, %117
%119 = call i32 @generic_open_read_write(i8* %113, i32 %118, i32 438)
store i32 %119, i32* %3
%120 = load i32, i32* %3
%121 = icmp ne i32 0, %120
br i1 %121, label %122, label %128
122: ; preds = %112
%123 = load i32, i32* @stderr
%124 = call i32 @fprintf(i32 %123, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
%125 = load i32, i32* %3
%126 = load i32, i32* %4
%127 = or i32 %126, %125
store i32 %127, i32* %4
br label %128
128: ; preds = %122, %112
%129 = load i8*, i8** %2
%130 = call i32 @creat(i8* %129, i32 420)
store i32 %130, i32* %3
%131 = load i32, i32* %3
%132 = call i32 @close(i32 %131)
%133 = load i8*, i8** %2
%134 = load i32, i32* @O_CREAT
%135 = load i32, i32* @O_EXCL
%136 = or i32 %134, %135
%137 = call i32 @generic_open_read_write(i8* %133, i32 %136, i32 438)
store i32 %137, i32* %3
%138 = load i32, i32* %3
%139 = icmp ne i32 0, %138
br i1 %139, label %140, label %146
140: ; preds = %128
%141 = load i32, i32* @stderr
%142 = call i32 @fprintf(i32 %141, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%143 = load i32, i32* %3
%144 = load i32, i32* %4
%145 = or i32 %144, %143
store i32 %145, i32* %4
br label %146
146: ; preds = %140, %128
%147 = load i32, i32* %4
ret i32 %147
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"flag O_CREAT|O_WRONLY failed: \0A\00"
@O_RDWR = global i32 0
@.str.1 = [28 x i8] c"flag O_CREAT|O_RDWR failed\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [30 x i8] c"flag O_CREAT|O_RDONLY failed\0A\00"
@.str.3 = [22 x i8] c"flag O_WRONLY failed\0A\00"
@.str.4 = [20 x i8] c"flag O_RDWR failed\0A\00"
@.str.5 = [22 x i8] c"flag O_RDONLY failed\0A\00"
@O_TRUNC = global i32 0
@.str.6 = [30 x i8] c"flag O_TRUNC|O_WRONLY failed\0A\00"
@O_SYNC = global i32 0
@.str.7 = [35 x i8] c"flag O_CREAT|O_RDWR|O_SYNC failed\0A\00"
@O_EXCL = global i32 0
@.str.8 = [28 x i8] c"flag O_CREAT|O_EXCL failed\0A\00"
define i32 @test_open_modes(i8* %0) {
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_WRONLY
%4 = or i32 %3, %2
%5 = tail call i32 @generic_open_read_write(i8* %0, i32 %4, i32 438)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = load i32, i32* @O_CREAT
%12 = load i32, i32* @O_RDWR
%13 = or i32 %12, %11
%14 = tail call i32 @generic_open_read_write(i8* %0, i32 %13, i32 438)
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%19 = or i32 %14, %5
br label %20
20: ; preds = %16, %10
%21 = phi i32 [ %19, %16 ], [ %5, %10 ]
%22 = load i32, i32* @O_CREAT
%23 = load i32, i32* @O_RDONLY
%24 = or i32 %23, %22
%25 = tail call i32 @generic_open_read_write(i8* %0, i32 %24, i32 438)
%26 = icmp eq i32 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%30 = or i32 %25, %21
br label %31
31: ; preds = %27, %20
%32 = phi i32 [ %30, %27 ], [ %21, %20 ]
%33 = tail call i32 @creat(i8* %0, i32 420)
%34 = tail call i32 @close(i32 %33)
%35 = load i32, i32* @O_WRONLY
%36 = tail call i32 @generic_open_read_write(i8* %0, i32 %35, i32 0)
%37 = icmp eq i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = tail call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%41 = or i32 %36, %32
br label %42
42: ; preds = %38, %31
%43 = phi i32 [ %41, %38 ], [ %32, %31 ]
%44 = tail call i32 @creat(i8* %0, i32 420)
%45 = tail call i32 @close(i32 %44)
%46 = load i32, i32* @O_RDWR
%47 = tail call i32 @generic_open_read_write(i8* %0, i32 %46, i32 0)
%48 = icmp eq i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%52 = or i32 %47, %43
br label %53
53: ; preds = %49, %42
%54 = phi i32 [ %52, %49 ], [ %43, %42 ]
%55 = tail call i32 @creat(i8* %0, i32 420)
%56 = tail call i32 @close(i32 %55)
%57 = load i32, i32* @O_RDONLY
%58 = tail call i32 @generic_open_read_write(i8* %0, i32 %57, i32 0)
%59 = icmp eq i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %53
%61 = load i32, i32* @stderr
%62 = tail call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%63 = or i32 %58, %54
br label %64
64: ; preds = %60, %53
%65 = phi i32 [ %63, %60 ], [ %54, %53 ]
%66 = tail call i32 @creat(i8* %0, i32 420)
%67 = tail call i32 @close(i32 %66)
%68 = load i32, i32* @O_TRUNC
%69 = load i32, i32* @O_WRONLY
%70 = or i32 %69, %68
%71 = tail call i32 @generic_open_read_write(i8* %0, i32 %70, i32 0)
%72 = icmp eq i32 %71, 0
br i1 %72, label %77, label %73
73: ; preds = %64
%74 = load i32, i32* @stderr
%75 = tail call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
%76 = or i32 %71, %65
br label %77
77: ; preds = %73, %64
%78 = phi i32 [ %76, %73 ], [ %65, %64 ]
%79 = load i32, i32* @O_CREAT
%80 = load i32, i32* @O_RDWR
%81 = or i32 %80, %79
%82 = load i32, i32* @O_SYNC
%83 = or i32 %81, %82
%84 = tail call i32 @generic_open_read_write(i8* %0, i32 %83, i32 438)
%85 = icmp eq i32 %84, 0
br i1 %85, label %90, label %86
86: ; preds = %77
%87 = load i32, i32* @stderr
%88 = tail call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0))
%89 = or i32 %84, %78
br label %90
90: ; preds = %86, %77
%91 = phi i32 [ %89, %86 ], [ %78, %77 ]
%92 = tail call i32 @creat(i8* %0, i32 420)
%93 = tail call i32 @close(i32 %92)
%94 = load i32, i32* @O_CREAT
%95 = load i32, i32* @O_EXCL
%96 = or i32 %95, %94
%97 = tail call i32 @generic_open_read_write(i8* %0, i32 %96, i32 438)
%98 = icmp eq i32 %97, 0
br i1 %98, label %103, label %99
99: ; preds = %90
%100 = load i32, i32* @stderr
%101 = tail call i32 @fprintf(i32 %100, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
%102 = or i32 %97, %91
br label %103
103: ; preds = %99, %90
%104 = phi i32 [ %102, %99 ], [ %91, %90 ]
ret i32 %104
}