#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__ 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_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    $0x60,%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    0x2e70(%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    0x2e59(%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    120b <dump_lock+0xeb>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    0x2db6(%rip),%rcx
cmp    (%rcx),%rax
jne    123b <dump_lock+0x11b>
lea    0xdfe(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1266 <dump_lock+0x146>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
mov    0x2d9e(%rip),%rax
mov    (%rax),%rsi
lea    0xde4(%rip),%rax
lea    0xdd9(%rip),%rcx
cmp    %rsi,%rdx
cmove  %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%r9
mov    -0x40(%rbp),%r8
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%esi
mov    -0x58(%rbp),%rax
lea    0xd7c(%rip),%rdi
mov    %rax,(%rsp)
call   1040 <printf@plt>
add    $0x60,%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    0x2e88(%rip),%r10
mov    0x2e91(%rip),%rdx
mov    (%rbx),%rsi
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rcx
lea    (%rcx,%rdi,1),%r9
test   %rdi,%rdi
mov    %r9,%r8
cmovg  %rcx,%r8
cmovle %rcx,%r9
cmp    (%rdx),%rsi
lea    0xebc(%rip),%rcx
lea    0xebc(%rip),%rdx
cmove  %rcx,%rdx
cmp    (%r10),%rsi
lea    0xea0(%rip),%rcx
cmovne %rdx,%rcx
mov    0x18(%rbx),%rdx
mov    0x2e4e(%rip),%rsi
mov    0x2e57(%rip),%rdi
cmp    (%rdi),%rdx
lea    0xe99(%rip),%rdi
lea    0xe96(%rip),%rbx
cmove  %rdi,%rbx
cmp    (%rsi),%rdx
lea    0xe80(%rip),%rdx
cmovne %rbx,%rdx
mov    %rdx,(%rsp)
lea    0xe41(%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"
@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 %57
53: ; preds = %39
%54 = load %struct.flock*, %struct.flock** %4
%55 = getelementptr inbounds %struct.flock, %struct.flock* %54, i32 0, i32 2
%56 = load i64, i64* %55
br label %57
57: ; preds = %53, %45
%58 = phi i64 [ %52, %45 ], [ %56, %53 ]
%59 = load %struct.flock*, %struct.flock** %4
%60 = getelementptr inbounds %struct.flock, %struct.flock* %59, i32 0, i32 3
%61 = load i64, i64* %60
%62 = load i64, i64* @SEEK_SET
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %65
64: ; preds = %57
br label %73
65: ; preds = %57
%66 = load %struct.flock*, %struct.flock** %4
%67 = getelementptr inbounds %struct.flock, %struct.flock* %66, i32 0, i32 3
%68 = load i64, i64* %67
%69 = load i64, i64* @SEEK_CUR
%70 = icmp eq i64 %68, %69
%71 = zext i1 %70 to i64
%72 = select i1 %70, 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 %73
73: ; preds = %65, %64
%74 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %64 ], [ %72, %65 ]
%75 = 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 %58, i8* %74)
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"
@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 = select i1 %10, i64 %12, i64 %13
%15 = select i1 %10, i64 %13, i64 %12
%16 = icmp eq i64 %5, %6
%17 = icmp eq i64 %5, %7
%18 = select i1 %17, 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)
%19 = select i1 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %18
%20 = getelementptr inbounds %struct.flock, %struct.flock* %1, i64 0, i32 3
%21 = load i64, i64* %20
%22 = load i64, i64* @SEEK_SET
%23 = icmp eq i64 %21, %22
%24 = load i64, i64* @SEEK_CUR
%25 = icmp eq i64 %21, %24
%26 = select i1 %25, 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)
%27 = select i1 %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %26
%28 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %3, i8* %0, i8* %19, i64 %14, i64 %15, i8* %27)
ret void
}