#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;
  scalar_t__ l_len;
  scalar_t__ l_start;
  scalar_t__ l_whence;
};

/* Variables and functions */
scalar_t__ F_RDLCK;
scalar_t__ F_WRLCK;
scalar_t__ INT_MAX;
scalar_t__ SEEK_CUR;
scalar_t__ SEEK_SET;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char const *, char *,
                          scalar_t__, scalar_t__, char *);
void dump_lock(char const *act, struct flock *lck) {
  printf(
      "[%lu] %s %s (%d, %d) @ %s\n", getpid(), act,
      lck->l_type == F_RDLCK ? "rdlock"
                             : (lck->l_type == F_WRLCK ? "wrlock" : "unlock"),
      lck->l_len > 0 ? lck->l_start : lck->l_start + lck->l_len,
      lck->l_len > 0    ? lck->l_start + lck->l_len
      : lck->l_len == 0 ? INT_MAX
                        : lck->l_start,
      lck->l_whence == SEEK_SET ? "beg"
                                : (lck->l_whence == SEEK_CUR ? "cur" : "end"));
}


x86 assembly (clang, -O0):
<dump_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    1169 <dump_lock+0x49>
lea    0xebb(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1193 <dump_lock+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    0x2e51(%rip),%rax
mov    (%rax),%rsi
lea    0xea8(%rip),%rax
lea    0xe9a(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jle    11bb <dump_lock+0x9b>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    11cf <dump_lock+0xaf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x10(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jle    11ff <dump_lock+0xdf>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    -0x10(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x48(%rbp)
jmp    1235 <dump_lock+0x115>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1221 <dump_lock+0x101>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    122d <dump_lock+0x10d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%rax
jne    1265 <dump_lock+0x145>
lea    0xdd4(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1290 <dump_lock+0x170>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    0x2d74(%rip),%rax
mov    (%rax),%rsi
lea    0xdba(%rip),%rax
lea    0xdaf(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%r9
mov    -0x40(%rbp),%r8
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%esi
mov    -0x60(%rbp),%rax
lea    0xd52(%rip),%rdi
mov    %rax,(%rsp)
call   1040 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_lock>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <getpid@plt>
mov    0x2e80(%rip),%r10
mov    0x2e89(%rip),%rdx
mov    (%rbx),%rsi
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%r8
lea    (%r8,%rdi,1),%rcx
test   %rdi,%rdi
mov    0x2e88(%rip),%rdi
mov    (%rdi),%r9
cmovne %r8,%r9
cmovle %rcx,%r8
cmovg  %rcx,%r9
cmp    (%rdx),%rsi
lea    0xeb1(%rip),%rcx
lea    0xeb1(%rip),%rdx
cmove  %rcx,%rdx
cmp    (%r10),%rsi
lea    0xe95(%rip),%rcx
cmovne %rdx,%rcx
mov    0x18(%rbx),%rdx
mov    0x2e3b(%rip),%rsi
mov    0x2e4c(%rip),%rdi
cmp    (%rdi),%rdx
lea    0xe8e(%rip),%rdi
lea    0xe8b(%rip),%rbx
cmove  %rdi,%rbx
cmp    (%rsi),%rdx
lea    0xe75(%rip),%rdx
cmovne %rbx,%rdx
mov    %rdx,(%rsp)
lea    0xe36(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i64, i64 }
@.str = [27 x i8] c"[%lu] %s %s (%d, %d) @ %s\0A\00"
@F_RDLCK = global i64 0
@.str.1 = [7 x i8] c"rdlock\00"
@F_WRLCK = global i64 0
@.str.2 = [7 x i8] c"wrlock\00"
@.str.3 = [7 x i8] c"unlock\00"
@INT_MAX = global i64 0
@SEEK_SET = global i64 0
@.str.4 = [4 x i8] c"beg\00"
@SEEK_CUR = global i64 0
@.str.5 = [4 x i8] c"cur\00"
@.str.6 = [4 x i8] c"end\00"
define void @dump_lock(i8* %0, %struct.flock* %1) {
%3 = alloca i8*
%4 = alloca %struct.flock*
store i8* %0, i8** %3
store %struct.flock* %1, %struct.flock** %4
%5 = call i32 (...) @getpid()
%6 = load i8*, i8** %3
%7 = load %struct.flock*, %struct.flock** %4
%8 = getelementptr inbounds %struct.flock, %struct.flock* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* @F_RDLCK
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
br label %21
13: ; preds = %2
%14 = load %struct.flock*, %struct.flock** %4
%15 = getelementptr inbounds %struct.flock, %struct.flock* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @F_WRLCK
%18 = icmp eq i64 %16, %17
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
br label %21
21: ; preds = %13, %12
%22 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %12 ], [ %20, %13 ]
%23 = load %struct.flock*, %struct.flock** %4
%24 = getelementptr inbounds %struct.flock, %struct.flock* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load %struct.flock*, %struct.flock** %4
%29 = getelementptr inbounds %struct.flock, %struct.flock* %28, i32 0, i32 2
%30 = load i64, i64* %29
br label %39
31: ; preds = %21
%32 = load %struct.flock*, %struct.flock** %4
%33 = getelementptr inbounds %struct.flock, %struct.flock* %32, i32 0, i32 2
%34 = load i64, i64* %33
%35 = load %struct.flock*, %struct.flock** %4
%36 = getelementptr inbounds %struct.flock, %struct.flock* %35, i32 0, i32 1
%37 = load i64, i64* %36
%38 = add nsw i64 %34, %37
br label %39
39: ; preds = %31, %27
%40 = phi i64 [ %30, %27 ], [ %38, %31 ]
%41 = load %struct.flock*, %struct.flock** %4
%42 = getelementptr inbounds %struct.flock, %struct.flock* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = icmp sgt i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %39
%46 = load %struct.flock*, %struct.flock** %4
%47 = getelementptr inbounds %struct.flock, %struct.flock* %46, i32 0, i32 2
%48 = load i64, i64* %47
%49 = load %struct.flock*, %struct.flock** %4
%50 = getelementptr inbounds %struct.flock, %struct.flock* %49, i32 0, i32 1
%51 = load i64, i64* %50
%52 = add nsw i64 %48, %51
br label %66
53: ; preds = %39
%54 = load %struct.flock*, %struct.flock** %4
%55 = getelementptr inbounds %struct.flock, %struct.flock* %54, i32 0, i32 1
%56 = load i64, i64* %55
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = load i64, i64* @INT_MAX
br label %64
60: ; preds = %53
%61 = load %struct.flock*, %struct.flock** %4
%62 = getelementptr inbounds %struct.flock, %struct.flock* %61, i32 0, i32 2
%63 = load i64, i64* %62
br label %64
64: ; preds = %60, %58
%65 = phi i64 [ %59, %58 ], [ %63, %60 ]
br label %66
66: ; preds = %64, %45
%67 = phi i64 [ %52, %45 ], [ %65, %64 ]
%68 = load %struct.flock*, %struct.flock** %4
%69 = getelementptr inbounds %struct.flock, %struct.flock* %68, i32 0, i32 3
%70 = load i64, i64* %69
%71 = load i64, i64* @SEEK_SET
%72 = icmp eq i64 %70, %71
br i1 %72, label %73, label %74
73: ; preds = %66
br label %82
74: ; preds = %66
%75 = load %struct.flock*, %struct.flock** %4
%76 = getelementptr inbounds %struct.flock, %struct.flock* %75, i32 0, i32 3
%77 = load i64, i64* %76
%78 = load i64, i64* @SEEK_CUR
%79 = icmp eq i64 %77, %78
%80 = zext i1 %79 to i64
%81 = select i1 %79, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
br label %82
82: ; preds = %74, %73
%83 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %73 ], [ %81, %74 ]
%84 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %6, i8* %22, i64 %40, i64 %67, i8* %83)
ret void
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i64, i64 }
@.str = [27 x i8] c"[%lu] %s %s (%d, %d) @ %s\0A\00"
@F_RDLCK = global i64 0
@.str.1 = [7 x i8] c"rdlock\00"
@F_WRLCK = global i64 0
@.str.2 = [7 x i8] c"wrlock\00"
@.str.3 = [7 x i8] c"unlock\00"
@INT_MAX = global i64 0
@SEEK_SET = global i64 0
@.str.4 = [4 x i8] c"beg\00"
@SEEK_CUR = global i64 0
@.str.5 = [4 x i8] c"cur\00"
@.str.6 = [4 x i8] c"end\00"
define void @dump_lock(i8* %0, %struct.flock* nocapture %1) {
%3 = tail call i32 (...) @getpid()
%4 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @F_RDLCK
%7 = load i64, i64* @F_WRLCK
%8 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = icmp sgt i64 %9, 0
%11 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 2
%12 = load i64, i64* %11
%13 = add nsw i64 %12, %9
%14 = icmp eq i64 %9, 0
%15 = load i64, i64* @INT_MAX
%16 = select i1 %14, i64 %15, i64 %12
%17 = select i1 %10, i64 %12, i64 %13
%18 = select i1 %10, i64 %13, i64 %16
%19 = icmp eq i64 %5, %6
%20 = icmp eq i64 %5, %7
%21 = select i1 %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%22 = select i1 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %21
%23 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 3
%24 = load i64, i64* %23
%25 = load i64, i64* @SEEK_SET
%26 = icmp eq i64 %24, %25
%27 = load i64, i64* @SEEK_CUR
%28 = icmp eq i64 %24, %27
%29 = select i1 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0)
%30 = select i1 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %29
%31 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %0, i8* %22, i64 %17, i64 %18, i8* %30)
ret void
}