#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 */
#define F_DUPFD 135
#define F_GETFD 134
#define F_GETFL 133
#define F_GETLK 132
#define F_SETFD 131
#define F_SETFL 130
#define F_SETLK 129
#define F_SETLKW 128
int dup(int);
int fcntl(int fd, int cmd, ...) {
  switch (cmd) {
  case F_DUPFD:
    return dup(fd);
  case F_GETFD:
  case F_SETFD:
  case F_GETFL:
  case F_SETFL:
    return 0;
  case F_GETLK:
  case F_SETLK:
  case F_SETLKW:
    return -1;
  }
  return -1;
}


x86 assembly (clang, -O0):
<fcntl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     11a3 <fcntl+0x93>
jmp    1135 <fcntl+0x25>
mov    -0x10(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x2,%eax
jb     1197 <fcntl+0x87>
jmp    114b <fcntl+0x3b>
mov    -0x10(%rbp),%eax
sub    $0x84,%eax
je     11a3 <fcntl+0x93>
jmp    115e <fcntl+0x4e>
mov    -0x10(%rbp),%eax
add    $0xffffff7b,%eax
sub    $0x2,%eax
jb     1197 <fcntl+0x87>
jmp    1174 <fcntl+0x64>
mov    -0x10(%rbp),%eax
sub    $0x87,%eax
jne    11af <fcntl+0x9f>
jmp    1187 <fcntl+0x77>
mov    -0x8(%rbp),%edi
call   1030 <dup@plt>
mov    %eax,-0x4(%rbp)
jmp    11b6 <fcntl+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <fcntl+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <fcntl+0xa6>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcntl>:
add    $0xffffff80,%esi
cmp    $0x7,%esi
ja     112e <fcntl+0x1e>
xor    %eax,%eax
mov    $0x6c,%ecx
bt     %esi,%ecx
jb     1133 <fcntl+0x23>
mov    $0x13,%eax
bt     %esi,%eax
jae    1134 <fcntl+0x24>
mov    $0xffffffff,%eax
ret
jmp    1030 <dup@plt>

LLVM IR (-O0):
define i32 @fcntl(i32 %0, i32 %1, ...) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
switch i32 %6, label %12 [
i32 135, label %7
i32 134, label %10
i32 131, label %10
i32 133, label %10
i32 130, label %10
i32 132, label %11
i32 129, label %11
i32 128, label %11
]
7: ; preds = %2
%8 = load i32, i32* %4
%9 = call i32 @dup(i32 %8)
store i32 %9, i32* %3
br label %13
10: ; preds = %2, %2, %2, %2
store i32 0, i32* %3
br label %13
11: ; preds = %2, %2, %2
store i32 -1, i32* %3
br label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %13
13: ; preds = %12, %11, %10, %7
%14 = load i32, i32* %3
ret i32 %14
}

LLVM IR (-O2):
define i32 @fcntl(i32 %0, i32 %1, ...) {
switch i32 %1, label %6 [
i32 135, label %3
i32 134, label %7
i32 131, label %7
i32 133, label %7
i32 130, label %7
i32 132, label %5
i32 129, label %5
i32 128, label %5
]
3: ; preds = %2
%4 = tail call i32 @dup(i32 %0)
br label %7
5: ; preds = %2, %2, %2
br label %7
6: ; preds = %2
br label %7
7: ; preds = %2, %2, %2, %2, %6, %5, %3
%8 = phi i32 [ -1, %6 ], [ -1, %5 ], [ %4, %3 ], [ 0, %2 ], [ 0, %2 ], [ 0, %2 ], [ 0, %2 ]
ret i32 %8
}