#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_APPEND;
int O_TRUNC;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
char *mode_str(int mode) {
  static char buf[512];
  buf[0] = 0;
  if (mode & O_APPEND) {
    strcat(buf, "O_APPEND|");
    mode &= ~O_APPEND;
  }
  if (mode & O_TRUNC) {
    strcat(buf, "O_TRUNC|");
    mode &= ~O_TRUNC;
  }
  switch (mode) {
  case 0:
    strcat(buf, "O_RDONLY");
    break;
  case 1:
    strcat(buf, "O_WRONLY");
    break;
  case 2:
    strcat(buf, "O_RDWR");
    break;
  default:
    assert(0);
  }
  return buf;
}


x86 assembly (clang, -O0):
<mode_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,0x2f0e(%rip)
mov    -0x4(%rbp),%eax
mov    0x2e94(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     116c <mode_str+0x4c>
lea    0x2ef2(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1040 <strcat@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e82(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a6 <mode_str+0x86>
lea    0x2eb8(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcat@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
test   %eax,%eax
je     11db <mode_str+0xbb>
jmp    11b9 <mode_str+0x99>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
je     11f3 <mode_str+0xd3>
jmp    11ca <mode_str+0xaa>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
je     120b <mode_str+0xeb>
jmp    1223 <mode_str+0x103>
lea    0x2e5e(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   1040 <strcat@plt>
jmp    122a <mode_str+0x10a>
lea    0x2e46(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   1040 <strcat@plt>
jmp    122a <mode_str+0x10a>
lea    0x2e2e(%rip),%rdi
lea    0xe0c(%rip),%rsi
call   1040 <strcat@plt>
jmp    122a <mode_str+0x10a>
xor    %edi,%edi
call   1030 <assert@plt>
lea    0x2e0f(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_str>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movb   $0x0,0x2f13(%rip)
mov    0x2e9c(%rip),%r14
test   %edi,(%r14)
je     1153 <mode_str+0x33>
lea    0x2f00(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1040 <strcat@plt>
mov    (%r14),%eax
not    %eax
and    %eax,%ebx
mov    0x2e9e(%rip),%r14
test   %ebx,(%r14)
je     1179 <mode_str+0x59>
lea    0x2eda(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <strcat@plt>
mov    (%r14),%eax
not    %eax
and    %eax,%ebx
cmp    $0x2,%ebx
je     119c <mode_str+0x7c>
cmp    $0x1,%ebx
je     11b1 <mode_str+0x91>
test   %ebx,%ebx
jne    11c6 <mode_str+0xa6>
lea    0x2eb2(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <strcat@plt>
jmp    11cd <mode_str+0xad>
lea    0x2e9d(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcat@plt>
jmp    11cd <mode_str+0xad>
lea    0x2e88(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcat@plt>
jmp    11cd <mode_str+0xad>
xor    %edi,%edi
call   1030 <assert@plt>
lea    0x2e6c(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@mode_str.buf = internal global [512 x i8] zeroinitializer
@O_APPEND = global i32 0
@.str = [10 x i8] c"O_APPEND|\00"
@O_TRUNC = global i32 0
@.str.1 = [9 x i8] c"O_TRUNC|\00"
@.str.2 = [9 x i8] c"O_RDONLY\00"
@.str.3 = [9 x i8] c"O_WRONLY\00"
@.str.4 = [7 x i8] c"O_RDWR\00"
define i8* @mode_str(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0)
%3 = load i32, i32* %2
%4 = load i32, i32* @O_APPEND
%5 = and i32 %3, %4
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @O_APPEND
%10 = xor i32 %9, -1
%11 = load i32, i32* %2
%12 = and i32 %11, %10
store i32 %12, i32* %2
br label %13
13: ; preds = %7, %1
%14 = load i32, i32* %2
%15 = load i32, i32* @O_TRUNC
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @O_TRUNC
%21 = xor i32 %20, -1
%22 = load i32, i32* %2
%23 = and i32 %22, %21
store i32 %23, i32* %2
br label %24
24: ; preds = %18, %13
%25 = load i32, i32* %2
switch i32 %25, label %32 [
i32 0, label %26
i32 1, label %28
i32 2, label %30
]
26: ; preds = %24
%27 = call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %34
28: ; preds = %24
%29 = call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %34
30: ; preds = %24
%31 = call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %34
32: ; preds = %24
%33 = call i32 @assert(i32 0)
br label %34
34: ; preds = %32, %30, %28, %26
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@mode_str.buf = internal global [512 x i8] zeroinitializer
@O_APPEND = global i32 0
@.str = [10 x i8] c"O_APPEND|\00"
@O_TRUNC = global i32 0
@.str.1 = [9 x i8] c"O_TRUNC|\00"
@.str.2 = [9 x i8] c"O_RDONLY\00"
@.str.3 = [9 x i8] c"O_WRONLY\00"
@.str.4 = [7 x i8] c"O_RDWR\00"
define i8* @mode_str(i32 %0) {
store i8 0, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0)
%2 = load i32, i32* @O_APPEND
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = tail call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @O_APPEND
%8 = xor i32 %7, -1
%9 = and i32 %8, %0
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ %9, %5 ], [ %0, %1 ]
%12 = load i32, i32* @O_TRUNC
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = tail call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @O_TRUNC
%18 = xor i32 %17, -1
%19 = and i32 %11, %18
br label %20
20: ; preds = %15, %10
%21 = phi i32 [ %19, %15 ], [ %11, %10 ]
switch i32 %21, label %28 [
i32 0, label %22
i32 1, label %24
i32 2, label %26
]
22: ; preds = %20
%23 = tail call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %30
24: ; preds = %20
%25 = tail call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %30
26: ; preds = %20
%27 = tail call i32 @strcat(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %30
28: ; preds = %20
%29 = tail call i32 @assert(i32 0)
br label %30
30: ; preds = %28, %26, %24, %22
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @mode_str.buf, i64 0, i64 0)
}