#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 */
struct flock {
  scalar_t__ l_type;
  int l_pid;
  scalar_t__ l_len;
  scalar_t__ l_start;
  scalar_t__ l_whence;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ path;
typedef int __s32;

/* Variables and functions */
int FD_CLOEXEC;
int /*<<< orphan*/ F_GETFD;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_GETLK;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
int O_APPEND;
int O_DSYNC;
int O_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int O_RSYNC;
int O_SYNC;
int O_WRONLY;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int readlink(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
void showFDDetail(__s32 fd) {
  char buf[256];
  __s32 fd_flags = fcntl(fd, F_GETFD);
  if (fd_flags == -1)
    return;
  int fl_flags = fcntl(fd, F_GETFL);
  if (fl_flags == -1)
    return;
  char path[256];
  snprintf(path, sizeof(path), "/proc/self/fd/%d", fd);
  memset(&buf[0], 0, 256);
  ssize_t s = readlink(path, &buf[0], 256);
  if (s == -1) {
    fprintf(stderr, " (%s): not available\n", path);
    return;
  }
  fprintf(stderr, "%d (%s): ", fd, buf);
  if (fd_flags & FD_CLOEXEC)
    fprintf(stderr, "cloexec ");
  if (fl_flags & O_APPEND)
    fprintf(stderr, "append ");
  if (fl_flags & O_NONBLOCK)
    fprintf(stderr, "nonblock ");
  if (fl_flags & O_RDONLY)
    fprintf(stderr, "read-only ");
  if (fl_flags & O_RDWR)
    fprintf(stderr, "read-write ");
  if (fl_flags & O_WRONLY)
    fprintf(stderr, "write-only ");
  if (fl_flags & O_DSYNC)
    fprintf(stderr, "dsync ");
  if (fl_flags & O_RSYNC)
    fprintf(stderr, "rsync ");
  if (fl_flags & O_SYNC)
    fprintf(stderr, "sync ");
  struct flock fl;
  fl.l_type = F_WRLCK;
  fl.l_whence = 0;
  fl.l_start = 0;
  fl.l_len = 0;
  fcntl(fd, F_GETLK, &fl);
  if (fl.l_type != F_UNLCK) {
    if (fl.l_type == F_WRLCK)
      fprintf(stderr, "write-locked");
    else
      fprintf(stderr, "read-locked");
    fprintf(stderr, "(pid:%d) ", fl.l_pid);
  }
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<showFDDetail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    1189 <showFDDetail+0x39>
jmp    14d9 <showFDDetail+0x389>
mov    -0x4(%rbp),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0xffffffff,-0x118(%rbp)
jne    11b4 <showFDDetail+0x64>
jmp    14d9 <showFDDetail+0x389>
lea    -0x220(%rbp),%rdi
mov    -0x4(%rbp),%ecx
mov    $0x100,%esi
lea    0xe36(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <readlink@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0xffffffff,-0x224(%rbp)
jne    1230 <showFDDetail+0xe0>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
lea    -0x220(%rbp),%rdx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    14d9 <showFDDetail+0x389>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    -0x110(%rbp),%rcx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x114(%rbp),%eax
mov    0x2d3a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1280 <showFDDetail+0x130>
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2cdb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12af <showFDDetail+0x15f>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2d14(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12de <showFDDetail+0x18e>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2cdd(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     130d <showFDDetail+0x1bd>
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2cc6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     133c <showFDDetail+0x1ec>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2c27(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     136b <showFDDetail+0x21b>
mov    0x2c45(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2c30(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     139a <showFDDetail+0x24a>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2c51(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13c9 <showFDDetail+0x279>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
lea    0xcb4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x118(%rbp),%eax
mov    0x2c02(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13f8 <showFDDetail+0x2a8>
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
lea    0xc7f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2b81(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x250(%rbp)
movq   $0x0,-0x230(%rbp)
movq   $0x0,-0x238(%rbp)
movq   $0x0,-0x240(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2b8c(%rip),%rax
mov    (%rax),%esi
lea    -0x250(%rbp),%rdx
mov    $0x0,%al
call   1040 <fcntl@plt>
mov    -0x250(%rbp),%rax
mov    0x2b66(%rip),%rcx
cmp    (%rcx),%rax
je     14c2 <showFDDetail+0x372>
mov    -0x250(%rbp),%rax
mov    0x2b17(%rip),%rcx
cmp    (%rcx),%rax
jne    148e <showFDDetail+0x33e>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
lea    0xbfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    14a5 <showFDDetail+0x355>
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
lea    0xbec(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2af4(%rip),%rax
mov    (%rax),%edi
mov    -0x248(%rbp),%edx
lea    0xbdb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2ad7(%rip),%rax
mov    (%rax),%edi
lea    0xb53(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showFDDetail>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x230,%rsp
mov    %edi,%r14d
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     13b2 <showFDDetail+0x262>
mov    %eax,%ebx
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
cmp    $0xffffffff,%eax
je     13b2 <showFDDetail+0x262>
mov    %eax,%r12d
lea    0xe5d(%rip),%rdx
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r14d,%ecx
call   1050 <snprintf@plt>
lea    0x130(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x100,%edx
call   1030 <readlink@plt>
mov    0x2dba(%rip),%rbp
mov    0x0(%rbp),%edi
cmp    $0xffffffff,%eax
je     139f <showFDDetail+0x24f>
lea    0xe2e(%rip),%rsi
lea    0x130(%rsp),%rcx
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d86(%rip),%rax
test   %ebx,(%rax)
je     1227 <showFDDetail+0xd7>
mov    0x0(%rbp),%edi
lea    0xe11(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d3a(%rip),%rax
test   %r12d,(%rax)
je     1244 <showFDDetail+0xf4>
mov    0x0(%rbp),%edi
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d85(%rip),%rax
test   %r12d,(%rax)
je     1261 <showFDDetail+0x111>
mov    0x0(%rbp),%edi
lea    0xde8(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d60(%rip),%rax
test   %r12d,(%rax)
je     127e <showFDDetail+0x12e>
mov    0x0(%rbp),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d5b(%rip),%rax
test   %r12d,(%rax)
je     129b <showFDDetail+0x14b>
mov    0x0(%rbp),%edi
lea    0xdc3(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cce(%rip),%rax
test   %r12d,(%rax)
je     12b8 <showFDDetail+0x168>
mov    0x0(%rbp),%edi
lea    0xdb2(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2ce9(%rip),%rax
test   %r12d,(%rax)
je     12d5 <showFDDetail+0x185>
mov    0x0(%rbp),%edi
lea    0xda1(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2d1c(%rip),%rax
test   %r12d,(%rax)
je     12f2 <showFDDetail+0x1a2>
mov    0x0(%rbp),%edi
lea    0xd8b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2cdf(%rip),%rax
test   %r12d,(%rax)
je     130f <showFDDetail+0x1bf>
mov    0x0(%rbp),%edi
lea    0xd68(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2c6a(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x8(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
mov    0x2c8a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %r14d,%edi
xor    %eax,%eax
call   1040 <fcntl@plt>
mov    0x8(%rsp),%rax
mov    0x2c65(%rip),%rcx
cmp    (%rcx),%rax
je     138c <showFDDetail+0x23c>
cmp    (%rbx),%rax
mov    0x0(%rbp),%edi
lea    0xd18(%rip),%rax
lea    0xd1e(%rip),%rsi
cmove  %rax,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
mov    0x10(%rsp),%edx
lea    0xd11(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xc8f(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13b2 <showFDDetail+0x262>
lea    0xc6b(%rip),%rsi
lea    0x30(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
add    $0x230,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i32, i64, i64, i64 }
@F_GETFD = global i32 0
@F_GETFL = global i32 0
@.str = [17 x i8] c"/proc/self/fd/%d\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c" (%s): not available\0A\00"
@.str.2 = [10 x i8] c"%d (%s): \00"
@FD_CLOEXEC = global i32 0
@.str.3 = [9 x i8] c"cloexec \00"
@O_APPEND = global i32 0
@.str.4 = [8 x i8] c"append \00"
@O_NONBLOCK = global i32 0
@.str.5 = [10 x i8] c"nonblock \00"
@O_RDONLY = global i32 0
@.str.6 = [11 x i8] c"read-only \00"
@O_RDWR = global i32 0
@.str.7 = [12 x i8] c"read-write \00"
@O_WRONLY = global i32 0
@.str.8 = [12 x i8] c"write-only \00"
@O_DSYNC = global i32 0
@.str.9 = [7 x i8] c"dsync \00"
@O_RSYNC = global i32 0
@.str.10 = [7 x i8] c"rsync \00"
@O_SYNC = global i32 0
@.str.11 = [6 x i8] c"sync \00"
@F_WRLCK = global i64 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.12 = [13 x i8] c"write-locked\00"
@.str.13 = [12 x i8] c"read-locked\00"
@.str.14 = [10 x i8] c"(pid:%d) \00"
@.str.15 = [2 x i8] c"\0A\00"
define void @showFDDetail(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca %struct.flock
store i32 %0, i32* %2
%9 = load i32, i32* %2
%10 = load i32, i32* @F_GETFD
%11 = call i32 (i32, i32, ...) @fcntl(i32 %9, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %1
br label %145
15: ; preds = %1
%16 = load i32, i32* %2
%17 = load i32, i32* @F_GETFL
%18 = call i32 (i32, i32, ...) @fcntl(i32 %16, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %15
br label %145
22: ; preds = %15
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %2
%25 = call i32 @snprintf(i8* %23, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 256)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%30 = call i32 @readlink(i8* %28, i8* %29, i32 256)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %145
37: ; preds = %22
%38 = load i32, i32* @stderr
%39 = load i32, i32* %2
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %39, i8* %40)
%42 = load i32, i32* %4
%43 = load i32, i32* @FD_CLOEXEC
%44 = and i32 %42, %43
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %37
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %46, %37
%50 = load i32, i32* %5
%51 = load i32, i32* @O_APPEND
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %57
57: ; preds = %54, %49
%58 = load i32, i32* %5
%59 = load i32, i32* @O_NONBLOCK
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %65
65: ; preds = %62, %57
%66 = load i32, i32* %5
%67 = load i32, i32* @O_RDONLY
%68 = and i32 %66, %67
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %73
73: ; preds = %70, %65
%74 = load i32, i32* %5
%75 = load i32, i32* @O_RDWR
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %81
81: ; preds = %78, %73
%82 = load i32, i32* %5
%83 = load i32, i32* @O_WRONLY
%84 = and i32 %82, %83
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %89
89: ; preds = %86, %81
%90 = load i32, i32* %5
%91 = load i32, i32* @O_DSYNC
%92 = and i32 %90, %91
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %89
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %97
97: ; preds = %94, %89
%98 = load i32, i32* %5
%99 = load i32, i32* @O_RSYNC
%100 = and i32 %98, %99
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %97
%103 = load i32, i32* @stderr
%104 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
br label %105
105: ; preds = %102, %97
%106 = load i32, i32* %5
%107 = load i32, i32* @O_SYNC
%108 = and i32 %106, %107
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %113
110: ; preds = %105
%111 = load i32, i32* @stderr
%112 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %113
113: ; preds = %110, %105
%114 = load i64, i64* @F_WRLCK
%115 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
store i64 %114, i64* %115
%116 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 4
store i64 0, i64* %116
%117 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 3
store i64 0, i64* %117
%118 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
store i64 0, i64* %118
%119 = load i32, i32* %2
%120 = load i32, i32* @F_GETLK
%121 = call i32 (i32, i32, ...) @fcntl(i32 %119, i32 %120, %struct.flock* %8)
%122 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
%123 = load i64, i64* %122
%124 = load i64, i64* @F_UNLCK
%125 = icmp ne i64 %123, %124
br i1 %125, label %126, label %142
126: ; preds = %113
%127 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
%128 = load i64, i64* %127
%129 = load i64, i64* @F_WRLCK
%130 = icmp eq i64 %128, %129
br i1 %130, label %131, label %134
131: ; preds = %126
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0))
br label %137
134: ; preds = %126
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
br label %137
137: ; preds = %134, %131
%138 = load i32, i32* @stderr
%139 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%140 = load i32, i32* %139
%141 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %140)
br label %142
142: ; preds = %137, %113
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %145
145: ; preds = %142, %33, %21, %14
ret void
}

LLVM IR (-O2):
%struct.flock = type { i64, i32, i64, i64, i64 }
@F_GETFD = global i32 0
@F_GETFL = global i32 0
@.str = [17 x i8] c"/proc/self/fd/%d\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c" (%s): not available\0A\00"
@.str.2 = [10 x i8] c"%d (%s): \00"
@FD_CLOEXEC = global i32 0
@.str.3 = [9 x i8] c"cloexec \00"
@O_APPEND = global i32 0
@.str.4 = [8 x i8] c"append \00"
@O_NONBLOCK = global i32 0
@.str.5 = [10 x i8] c"nonblock \00"
@O_RDONLY = global i32 0
@.str.6 = [11 x i8] c"read-only \00"
@O_RDWR = global i32 0
@.str.7 = [12 x i8] c"read-write \00"
@O_WRONLY = global i32 0
@.str.8 = [12 x i8] c"write-only \00"
@O_DSYNC = global i32 0
@.str.9 = [7 x i8] c"dsync \00"
@O_RSYNC = global i32 0
@.str.10 = [7 x i8] c"rsync \00"
@O_SYNC = global i32 0
@.str.11 = [6 x i8] c"sync \00"
@F_WRLCK = global i64 0
@F_GETLK = global i32 0
@F_UNLCK = global i64 0
@.str.12 = [13 x i8] c"write-locked\00"
@.str.13 = [12 x i8] c"read-locked\00"
@.str.14 = [10 x i8] c"(pid:%d) \00"
@.str.15 = [2 x i8] c"\0A\00"
define void @showFDDetail(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca %struct.flock
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @F_GETFD
%7 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %111, label %9
9: ; preds = %1
%10 = load i32, i32* @F_GETFL
%11 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %111, label %13
13: ; preds = %9
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = call i32 @snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%16 = call i32 @memset(i8* %5, i32 0, i32 256)
%17 = call i32 @readlink(i8* %14, i8* %5, i32 256)
%18 = icmp eq i32 %17, -1
%19 = load i32, i32* @stderr
br i1 %18, label %20, label %22
20: ; preds = %13
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %110
22: ; preds = %13
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %0, i8* %5)
%24 = load i32, i32* @FD_CLOEXEC
%25 = and i32 %24, %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %22
%31 = load i32, i32* @O_APPEND
%32 = and i32 %31, %11
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %34, %30
%38 = load i32, i32* @O_NONBLOCK
%39 = and i32 %38, %11
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %44
44: ; preds = %41, %37
%45 = load i32, i32* @O_RDONLY
%46 = and i32 %45, %11
%47 = icmp eq i32 %46, 0
br i1 %47, label %51, label %48
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %51
51: ; preds = %48, %44
%52 = load i32, i32* @O_RDWR
%53 = and i32 %52, %11
%54 = icmp eq i32 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %55, %51
%59 = load i32, i32* @O_WRONLY
%60 = and i32 %59, %11
%61 = icmp eq i32 %60, 0
br i1 %61, label %65, label %62
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %65
65: ; preds = %62, %58
%66 = load i32, i32* @O_DSYNC
%67 = and i32 %66, %11
%68 = icmp eq i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
br label %72
72: ; preds = %69, %65
%73 = load i32, i32* @O_RSYNC
%74 = and i32 %73, %11
%75 = icmp eq i32 %74, 0
br i1 %75, label %79, label %76
76: ; preds = %72
%77 = load i32, i32* @stderr
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0))
br label %79
79: ; preds = %76, %72
%80 = load i32, i32* @O_SYNC
%81 = and i32 %80, %11
%82 = icmp eq i32 %81, 0
br i1 %82, label %86, label %83
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0))
br label %86
86: ; preds = %83, %79
%87 = bitcast %struct.flock* %4 to i8*
%88 = load i64, i64* @F_WRLCK
%89 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i64 %88, i64* %89
%90 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
%91 = bitcast i64* %90 to i8*
%92 = load i32, i32* @F_GETLK
%93 = call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %92, %struct.flock* %4)
%94 = load i64, i64* %89
%95 = load i64, i64* @F_UNLCK
%96 = icmp eq i64 %94, %95
br i1 %96, label %107, label %97
97: ; preds = %86
%98 = load i64, i64* @F_WRLCK
%99 = icmp eq i64 %94, %98
%100 = load i32, i32* @stderr
%101 = select i1 %99, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0)
%102 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* %101)
%103 = load i32, i32* @stderr
%104 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
%105 = load i32, i32* %104
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.14, i64 0, i64 0), i32 %105)
br label %107
107: ; preds = %97, %86
%108 = load i32, i32* @stderr
%109 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %110
110: ; preds = %107, %20
br label %111
111: ; preds = %110, %9, %1
ret void
}