#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_whence;
  scalar_t__ l_start;
  scalar_t__ l_len;
  scalar_t__ l_pid;
};
typedef int /*<<< orphan*/ fl1;

/* Variables and functions */
int /*<<< orphan*/ F_GETLK;
scalar_t__ F_UNLCK;
scalar_t__ F_WRLCK;
scalar_t__ SEEK_SET;
int /*<<< orphan*/ err(int, char *);
scalar_t__ fcntl(int, int /*<<< orphan*/, struct flock *);
int /*<<< orphan*/ memset(struct flock *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int test1(int fd, int argc, const char **argv) {
  struct flock fl1, fl2;
  memset(&fl1, 1, sizeof(fl1));
  fl1.l_type = F_WRLCK;
  fl1.l_whence = SEEK_SET;
  fl2 = fl1;
  if (fcntl(fd, F_GETLK, &fl1) < 0)
    err(1, "F_GETLK");
  printf("1 - F_GETLK on unlocked region: ");
  do {
    if (fl1.l_start != fl2.l_start) {
      printf("FAIL (%s)\n", "fl1.l_start != fl2.l_start");
      return -1;
    }
  } while (0);
  do {
    if (fl1.l_len != fl2.l_len) {
      printf("FAIL (%s)\n", "fl1.l_len != fl2.l_len");
      return -1;
    }
  } while (0);
  do {
    if (fl1.l_pid != fl2.l_pid) {
      printf("FAIL (%s)\n", "fl1.l_pid != fl2.l_pid");
      return -1;
    }
  } while (0);
  do {
    if (fl1.l_type != F_UNLCK) {
      printf("FAIL (%s)\n", "fl1.l_type != F_UNLCK");
      return -1;
    }
  } while (0);
  do {
    if (fl1.l_whence != fl2.l_whence) {
      printf("FAIL (%s)\n", "fl1.l_whence != fl2.l_whence");
      return -1;
    }
  } while (0);
  do {
    printf("SUCCEED\n");
    return 0;
  } while (0);
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x68(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x28,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    -0x40(%rbp),%rdx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11d3 <test1+0x83>
mov    $0x1,%edi
lea    0xe32(%rip),%rsi
call   1070 <err@plt>
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
cmp    -0x58(%rbp),%rax
je     1210 <test1+0xc0>
lea    0xe33(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <test1+0x1c9>
jmp    1215 <test1+0xc5>
jmp    121a <test1+0xca>
mov    -0x28(%rbp),%rax
cmp    -0x50(%rbp),%rax
je     1249 <test1+0xf9>
lea    0xdfa(%rip),%rdi
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <test1+0x1c9>
jmp    124e <test1+0xfe>
jmp    1253 <test1+0x103>
mov    -0x20(%rbp),%rax
cmp    -0x48(%rbp),%rax
je     1282 <test1+0x132>
lea    0xdc1(%rip),%rdi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <test1+0x1c9>
jmp    1287 <test1+0x137>
jmp    128c <test1+0x13c>
mov    -0x40(%rbp),%rax
mov    0x2d49(%rip),%rcx
cmp    (%rcx),%rax
je     12c1 <test1+0x171>
lea    0xd82(%rip),%rdi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <test1+0x1c9>
jmp    12c6 <test1+0x176>
jmp    12cb <test1+0x17b>
mov    -0x38(%rbp),%rax
cmp    -0x60(%rbp),%rax
je     12fa <test1+0x1aa>
lea    0xd49(%rip),%rdi
lea    0xdac(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1319 <test1+0x1c9>
jmp    12ff <test1+0x1af>
jmp    1304 <test1+0x1b4>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rsp)
mov    0x2e46(%rip),%rax
mov    (%rax),%r15
mov    %r15,0x8(%rsp)
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%r13
mov    0x20(%rsp),%r12
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1040 <fcntl@plt>
test   %rax,%rax
jns    11ca <test1+0x7a>
lea    0xe40(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %rbp,0x10(%rsp)
jne    1214 <test1+0xc4>
cmp    %r13,0x18(%rsp)
jne    1224 <test1+0xd4>
cmp    %r12,0x20(%rsp)
jne    1234 <test1+0xe4>
mov    (%rsp),%rax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%rax
jne    1244 <test1+0xf4>
cmp    %r15,0x8(%rsp)
jne    1254 <test1+0x104>
lea    0xea5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    126e <test1+0x11e>
lea    0xe0e(%rip),%rdi
lea    0xe12(%rip),%rsi
jmp    1262 <test1+0x112>
lea    0xdfe(%rip),%rdi
lea    0xe1d(%rip),%rsi
jmp    1262 <test1+0x112>
lea    0xdee(%rip),%rdi
lea    0xe24(%rip),%rsi
jmp    1262 <test1+0x112>
lea    0xdde(%rip),%rdi
lea    0xe2b(%rip),%rsi
jmp    1262 <test1+0x112>
lea    0xdce(%rip),%rdi
lea    0xe31(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flock = type { i64, i64, i64, i64, i64 }
@F_WRLCK = global i64 0
@SEEK_SET = global i64 0
@F_GETLK = global i32 0
@.str = [8 x i8] c"F_GETLK\00"
@.str.1 = [33 x i8] c"1 - F_GETLK on unlocked region: \00"
@.str.2 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.3 = [27 x i8] c"fl1.l_start != fl2.l_start\00"
@.str.4 = [23 x i8] c"fl1.l_len != fl2.l_len\00"
@.str.5 = [23 x i8] c"fl1.l_pid != fl2.l_pid\00"
@F_UNLCK = global i64 0
@.str.6 = [22 x i8] c"fl1.l_type != F_UNLCK\00"
@.str.7 = [29 x i8] c"fl1.l_whence != fl2.l_whence\00"
@.str.8 = [9 x i8] c"SUCCEED\0A\00"
define i32 @test1(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca %struct.flock
%9 = alloca %struct.flock
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%10 = call i32 @memset(%struct.flock* %8, i32 1, i32 40)
%11 = load i64, i64* @F_WRLCK
%12 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
store i64 %11, i64* %12
%13 = load i64, i64* @SEEK_SET
%14 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
store i64 %13, i64* %14
%15 = bitcast %struct.flock* %9 to i8*
%16 = bitcast %struct.flock* %8 to i8*
%17 = load i32, i32* %5
%18 = load i32, i32* @F_GETLK
%19 = call i64 @fcntl(i32 %17, i32 %18, %struct.flock* %8)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23
%26 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 2
%27 = load i64, i64* %26
%28 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 2
%29 = load i64, i64* %28
%30 = icmp ne i64 %27, %29
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
33: ; preds = %25
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
%36 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 3
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 3
%39 = load i64, i64* %38
%40 = icmp ne i64 %37, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
43: ; preds = %35
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
%46 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 4
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 4
%49 = load i64, i64* %48
%50 = icmp ne i64 %47, %49
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
53: ; preds = %45
br label %54
54: ; preds = %53
br label %55
55: ; preds = %54
%56 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 0
%57 = load i64, i64* %56
%58 = load i64, i64* @F_UNLCK
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
62: ; preds = %55
br label %63
63: ; preds = %62
br label %64
64: ; preds = %63
%65 = getelementptr inbounds %struct.flock, %struct.flock* %8, i32 0, i32 1
%66 = load i64, i64* %65
%67 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 1
%68 = load i64, i64* %67
%69 = icmp ne i64 %66, %68
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
72: ; preds = %64
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
store i32 0, i32* %4
br label %76
76: ; preds = %31, %41, %51, %60, %70, %74
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
%struct.flock = type { i64, i64, i64, i64, i64 }
@F_WRLCK = global i64 0
@SEEK_SET = global i64 0
@F_GETLK = global i32 0
@.str = [8 x i8] c"F_GETLK\00"
@.str.1 = [33 x i8] c"1 - F_GETLK on unlocked region: \00"
@.str.2 = [11 x i8] c"FAIL (%s)\0A\00"
@.str.3 = [27 x i8] c"fl1.l_start != fl2.l_start\00"
@.str.4 = [23 x i8] c"fl1.l_len != fl2.l_len\00"
@.str.5 = [23 x i8] c"fl1.l_pid != fl2.l_pid\00"
@F_UNLCK = global i64 0
@.str.6 = [22 x i8] c"fl1.l_type != F_UNLCK\00"
@.str.7 = [29 x i8] c"fl1.l_whence != fl2.l_whence\00"
@str = [8 x i8] c"SUCCEED\00"
define i32 @test1(i32 %0, i32 %1, i8** nocapture readnone %2) {
%4 = alloca %struct.flock
%5 = bitcast %struct.flock* %4 to i8*
%6 = call i32 @memset(%struct.flock* %4, i32 1, i32 40)
%7 = load i64, i64* @F_WRLCK
%8 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 0
store i64 %7, i64* %8
%9 = load i64, i64* @SEEK_SET
%10 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 1
store i64 %9, i64* %10
%11 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 2
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 3
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.flock, %struct.flock* %4, i64 0, i32 4
%16 = load i64, i64* %15
%17 = load i32, i32* @F_GETLK
%18 = call i64 @fcntl(i32 %0, i32 %17, %struct.flock* %4)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %3
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%24 = load i64, i64* %11
%25 = icmp eq i64 %24, %12
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %51
28: ; preds = %22
%29 = load i64, i64* %13
%30 = icmp eq i64 %29, %14
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %51
33: ; preds = %28
%34 = load i64, i64* %15
%35 = icmp eq i64 %34, %16
br i1 %35, label %38, label %36
36: ; preds = %33
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %51
38: ; preds = %33
%39 = load i64, i64* %8
%40 = load i64, i64* @F_UNLCK
%41 = icmp eq i64 %39, %40
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %51
44: ; preds = %38
%45 = load i64, i64* %10
%46 = icmp eq i64 %45, %9
br i1 %46, label %49, label %47
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
br label %51
49: ; preds = %44
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %51
51: ; preds = %49, %47, %42, %36, %31, %26
%52 = phi i32 [ -1, %26 ], [ -1, %31 ], [ -1, %36 ], [ -1, %42 ], [ -1, %47 ], [ 0, %49 ]
ret i32 %52
}