#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_pid;
  int /*<<< orphan*/ l_len;
  int /*<<< orphan*/ l_start;
};

/* Variables and functions */
scalar_t__ F_RDLCK;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
int /*<<< orphan*/ printf(char *, ...);
void print_lock(struct flock lock) {
  if (lock.l_type != F_UNLCK) {
    printf("+++++++++++++++++\n");
    printf("Lock is present\n");
    if (lock.l_type == F_WRLCK) {
      printf("Type: Write\n");
    }
    if (lock.l_type == F_RDLCK) {
      printf("Type: Read\n");
    }
    printf("Offset: %ld\n", lock.l_start);
    printf("Length: %ld\n", lock.l_len);
    printf("Owner's PID: %ld\n", (long)lock.l_pid);
    printf("+++++++++++++++++\n");
  }
}


x86 assembly (clang, -O0):
<print_lock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    (%rax),%rax
mov    0x2ebe(%rip),%rcx
cmp    (%rcx),%rax
je     11e7 <print_lock+0xd7>
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1174 <print_lock+0x64>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    1199 <print_lock+0x89>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_lock>:
push   %r14
push   %rbx
push   %rax
mov    0x20(%rsp),%rbx
mov    0x2eb8(%rip),%rax
cmp    (%rax),%rbx
jne    113d <print_lock+0x1d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7c(%rip),%rax
cmp    (%rax),%rbx
jne    116d <print_lock+0x4d>
lea    0xef1(%rip),%rdi
call   1030 <puts@plt>
lea    0x20(%rsp),%r14
mov    0x2e4f(%rip),%rax
cmp    (%rax),%rbx
jne    118a <print_lock+0x6a>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    0x14(%r14),%esi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%r14),%esi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r14),%rsi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
%struct.flock = type { i64, i64, i32, i32 }
@F_UNLCK = global i64 0
@.str = [19 x i8] c"+++++++++++++++++\0A\00"
@.str.1 = [17 x i8] c"Lock is present\0A\00"
@F_WRLCK = global i64 0
@.str.2 = [13 x i8] c"Type: Write\0A\00"
@F_RDLCK = global i64 0
@.str.3 = [12 x i8] c"Type: Read\0A\00"
@.str.4 = [13 x i8] c"Offset: %ld\0A\00"
@.str.5 = [13 x i8] c"Length: %ld\0A\00"
@.str.6 = [18 x i8] c"Owner's PID: %ld\0A\00"
define void @print_lock(%struct.flock* byval(%struct.flock) align 8 %0) {
%2 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 0
%3 = load i64, i64* %2
%4 = load i64, i64* @F_UNLCK
%5 = icmp ne i64 %3, %4
br i1 %5, label %6, label %33
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @F_WRLCK
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %13, %6
%16 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @F_RDLCK
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 3
%24 = load i32, i32* %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 2
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds %struct.flock, %struct.flock* %0, i32 0, i32 1
%30 = load i64, i64* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %22, %1
ret void
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i32, i32 }
@F_UNLCK = global i64 0
@F_WRLCK = global i64 0
@F_RDLCK = global i64 0
@.str.4 = [13 x i8] c"Offset: %ld\0A\00"
@.str.5 = [13 x i8] c"Length: %ld\0A\00"
@.str.6 = [18 x i8] c"Owner's PID: %ld\0A\00"
@str.7 = [16 x i8] c"Lock is present\00"
@str.8 = [18 x i8] c"+++++++++++++++++\00"
@str.9 = [11 x i8] c"Type: Read\00"
@str.10 = [12 x i8] c"Type: Write\00"
define void @print_lock(%struct.flock* nocapture byval(%struct.flock) align 8 %0) {
%2 = getelementptr inbounds %struct.flock, %struct.flock* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = load i64, i64* @F_UNLCK
%5 = icmp eq i64 %3, %4
br i1 %5, label %29, label %6
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0))
%9 = load i64, i64* @F_WRLCK
%10 = icmp eq i64 %3, %9
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
br label %13
13: ; preds = %11, %6
%14 = load i64, i64* @F_RDLCK
%15 = icmp eq i64 %3, %14
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.9, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = getelementptr inbounds %struct.flock, %struct.flock* %0, i64 0, i32 3
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds %struct.flock, %struct.flock* %0, i64 0, i32 2
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds %struct.flock, %struct.flock* %0, i64 0, i32 1
%26 = load i64, i64* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i64 %26)
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %29
29: ; preds = %18, %1
ret void
}