#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 /*<<< orphan*/ F_SETFL;
int O_ACCMODE;
int O_APPEND;
int O_CREAT;
int O_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int O_SYNC;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ my_err(char *, int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int ret;
  int access_mode;
  int fd;
  if ((fd = open("example_fc_acc", O_CREAT | O_TRUNC | O_RDWR, S_IRWXU)) ==
      -1) {
    my_err("open", 36);
  }
  if ((ret = fcntl(fd, F_SETFL, O_APPEND)) < 0) {
    my_err("fcntl", 42);
  }
  if ((ret = fcntl(fd, F_GETFL, 0)) < 0) {
    my_err("fcntl", 47);
  }
  access_mode = ret & O_ACCMODE;
  if (access_mode == O_RDONLY) {
    printf("example_fc_acc access mode: read only");
  } else if (access_mode == O_WRONLY) {
    printf("example_fc_acc access mode: write only");
  } else if (access_mode == O_RDWR) {
    printf("example_fc_acc access mode: read + write");
  }
  if (ret & O_APPEND) {
    printf(", append");
  }
  if (ret & O_NONBLOCK) {
    printf(", nonblock");
  }
  if (ret & O_SYNC) {
    printf(", sync");
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    0x2e8a(%rip),%rax
or     (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    11a3 <main+0x63>
lea    0xe76(%rip),%rdi
mov    $0x24,%esi
call   1060 <my_err@plt>
mov    -0x1c(%rbp),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11da <main+0x9a>
lea    0xe44(%rip),%rdi
mov    $0x2a,%esi
call   1060 <my_err@plt>
mov    -0x1c(%rbp),%edi
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    120a <main+0xca>
lea    0xe14(%rip),%rdi
mov    $0x2f,%esi
call   1060 <my_err@plt>
mov    -0x14(%rbp),%eax
mov    0x2dcc(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%eax
jne    123c <main+0xfc>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
jmp    1287 <main+0x147>
mov    -0x18(%rbp),%eax
mov    0x2d42(%rip),%rcx
cmp    (%rcx),%eax
jne    125f <main+0x11f>
lea    0xdeb(%rip),%rdi
call   1040 <printf@plt>
jmp    1282 <main+0x142>
mov    -0x18(%rbp),%eax
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%eax
jne    127d <main+0x13d>
lea    0xdef(%rip),%rdi
call   1040 <printf@plt>
jmp    1282 <main+0x142>
jmp    1287 <main+0x147>
mov    -0x14(%rbp),%eax
mov    0x2cef(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12a8 <main+0x168>
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2d06(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12c9 <main+0x189>
lea    0xdd5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    0x2ced(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12ea <main+0x1aa>
lea    0xdbf(%rip),%rdi
call   1040 <printf@plt>
lea    0xdba(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e5a(%rip),%r14
or     (%r14),%esi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    119e <main+0x4e>
lea    0xe7b(%rip),%rdi
mov    $0x24,%esi
call   1070 <my_err@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%r15
mov    (%r15),%edx
mov    %ebx,%edi
call   1040 <fcntl@plt>
test   %eax,%eax
jns    11cd <main+0x7d>
lea    0xe51(%rip),%rdi
mov    $0x2a,%esi
call   1070 <my_err@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f6 <main+0xa6>
lea    0xe28(%rip),%rdi
mov    $0x2f,%esi
call   1070 <my_err@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
and    %ebx,%eax
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <main+0xc5>
lea    0xe07(%rip),%rdi
jmp    1235 <main+0xe5>
mov    0x2d6c(%rip),%rcx
cmp    (%rcx),%eax
jne    1229 <main+0xd9>
lea    0xe19(%rip),%rdi
jmp    1235 <main+0xe5>
cmp    (%r14),%eax
jne    123a <main+0xea>
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
test   %ebx,(%r15)
je     124b <main+0xfb>
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d66(%rip),%rax
test   %ebx,(%rax)
je     1262 <main+0x112>
lea    0xe3c(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d57(%rip),%rax
test   %ebx,(%rax)
je     1279 <main+0x129>
lea    0xe30(%rip),%rdi
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"example_fc_acc\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [5 x i8] c"open\00"
@F_SETFL = global i32 0
@O_APPEND = global i32 0
@.str.2 = [6 x i8] c"fcntl\00"
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [38 x i8] c"example_fc_acc access mode: read only\00"
@O_WRONLY = global i32 0
@.str.4 = [39 x i8] c"example_fc_acc access mode: write only\00"
@.str.5 = [41 x i8] c"example_fc_acc access mode: read + write\00"
@.str.6 = [9 x i8] c", append\00"
@O_NONBLOCK = global i32 0
@.str.7 = [11 x i8] c", nonblock\00"
@O_SYNC = global i32 0
@.str.8 = [7 x i8] c", sync\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @O_CREAT
%10 = load i32, i32* @O_TRUNC
%11 = or i32 %9, %10
%12 = load i32, i32* @O_RDWR
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IRWXU
%15 = call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
store i32 %15, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 36)
br label %19
19: ; preds = %17, %2
%20 = load i32, i32* %8
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* @O_APPEND
%23 = call i32 @fcntl(i32 %20, i32 %21, i32 %22)
store i32 %23, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 42)
br label %27
27: ; preds = %25, %19
%28 = load i32, i32* %8
%29 = load i32, i32* @F_GETFL
%30 = call i32 @fcntl(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 47)
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %6
%36 = load i32, i32* @O_ACCMODE
%37 = and i32 %35, %36
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = load i32, i32* @O_RDONLY
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %57
43: ; preds = %34
%44 = load i32, i32* %7
%45 = load i32, i32* @O_WRONLY
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0))
br label %56
49: ; preds = %43
%50 = load i32, i32* %7
%51 = load i32, i32* @O_RDWR
%52 = icmp eq i32 %50, %51
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %55
55: ; preds = %53, %49
br label %56
56: ; preds = %55, %47
br label %57
57: ; preds = %56, %41
%58 = load i32, i32* %6
%59 = load i32, i32* @O_APPEND
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
%65 = load i32, i32* %6
%66 = load i32, i32* @O_NONBLOCK
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %71
69: ; preds = %64
%70 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %71
71: ; preds = %69, %64
%72 = load i32, i32* %6
%73 = load i32, i32* @O_SYNC
%74 = and i32 %72, %73
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %78
76: ; preds = %71
%77 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %78
78: ; preds = %76, %71
%79 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"example_fc_acc\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDWR = global i32 0
@S_IRWXU = global i32 0
@.str.1 = [5 x i8] c"open\00"
@F_SETFL = global i32 0
@O_APPEND = global i32 0
@.str.2 = [6 x i8] c"fcntl\00"
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
@.str.3 = [38 x i8] c"example_fc_acc access mode: read only\00"
@O_WRONLY = global i32 0
@.str.4 = [39 x i8] c"example_fc_acc access mode: write only\00"
@.str.5 = [41 x i8] c"example_fc_acc access mode: read + write\00"
@.str.6 = [9 x i8] c", append\00"
@O_NONBLOCK = global i32 0
@.str.7 = [11 x i8] c", nonblock\00"
@O_SYNC = global i32 0
@.str.8 = [7 x i8] c", sync\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_TRUNC
%5 = or i32 %4, %3
%6 = load i32, i32* @O_RDWR
%7 = or i32 %5, %6
%8 = load i32, i32* @S_IRWXU
%9 = tail call i32 @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @my_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 36)
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* @F_SETFL
%15 = load i32, i32* @O_APPEND
%16 = tail call i32 @fcntl(i32 %9, i32 %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 42)
br label %20
20: ; preds = %18, %13
%21 = load i32, i32* @F_GETFL
%22 = tail call i32 @fcntl(i32 %9, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @my_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 47)
br label %26
26: ; preds = %24, %20
%27 = load i32, i32* @O_ACCMODE
%28 = and i32 %27, %22
%29 = load i32, i32* @O_RDONLY
%30 = icmp eq i32 %28, %29
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load i32, i32* @O_WRONLY
%33 = icmp eq i32 %28, %32
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* @O_RDWR
%36 = icmp eq i32 %28, %35
br i1 %36, label %37, label %40
37: ; preds = %34, %31, %26
%38 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), %26 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), %31 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), %34 ]
%39 = tail call i32 @printf(i8* dereferenceable(1) %38)
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* @O_APPEND
%42 = and i32 %41, %22
%43 = icmp eq i32 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = load i32, i32* @O_NONBLOCK
%48 = and i32 %47, %22
%49 = icmp eq i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %52
52: ; preds = %50, %46
%53 = load i32, i32* @O_SYNC
%54 = and i32 %53, %22
%55 = icmp eq i32 %54, 0
br i1 %55, label %58, label %56
56: ; preds = %52
%57 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %58
58: ; preds = %56, %52
%59 = tail call i32 @putchar(i32 10)
ret i32 0
}