#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 {
  int l_len;
  scalar_t__ l_start;
  int /*<<< orphan*/ l_whence;
  int /*<<< orphan*/ l_type;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ F_LOCK;
int /*<<< orphan*/ F_RDLCK;
int /*<<< orphan*/ F_SETLK;
int /*<<< orphan*/ LOCK_EX;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int fcntl(int, int /*<<< orphan*/, struct flock *);
int flock(int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lockf(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ t1_usage();
int t1(int argc, char *argv[]) {
  int fd;
  int mount_with_flock = 0;
  int error = 0;
  if (argc != 5) {
    t1_usage();
    return EXIT_FAILURE;
  }
  if (!strncmp(argv[2], "on", 3)) {
    mount_with_flock = 1;
  } else if (!strncmp(argv[2], "off", 4)) {
    mount_with_flock = 0;
  } else {
    t1_usage();
    return EXIT_FAILURE;
  }
  if ((fd = open(argv[4], O_RDWR)) < 0) {
    fprintf(stderr, "Couldn't open file: %s\n", argv[3]);
    return EXIT_FAILURE;
  }
  if (!strncmp(argv[3], "-c", 3)) {
    struct flock fl;
    fl.l_type = F_RDLCK;
    fl.l_whence = SEEK_SET;
    fl.l_start = 0;
    fl.l_len = 1;
    error = fcntl(fd, F_SETLK, &fl);
  } else if (!strncmp(argv[3], "-l", 3)) {
    error = lockf(fd, F_LOCK, 1);
  } else if (!strncmp(argv[3], "-f", 3)) {
    error = flock(fd, LOCK_EX);
  } else {
    t1_usage();
    return EXIT_FAILURE;
  }
  if (mount_with_flock)
    return ((error == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
  else
    return ((error == 0) ? EXIT_FAILURE : EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<t1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11af <t1+0x3f>
mov    $0x0,%al
call   1030 <t1_usage@plt>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e4 <t1+0x274>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe42(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    11dd <t1+0x6d>
movl   $0x1,-0x18(%rbp)
jmp    1228 <t1+0xb8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe17(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    120b <t1+0x9b>
movl   $0x0,-0x18(%rbp)
jmp    1223 <t1+0xb3>
mov    $0x0,%al
call   1030 <t1_usage@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e4 <t1+0x274>
jmp    1228 <t1+0xb8>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1278 <t1+0x108>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xda5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e4 <t1+0x274>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd98(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    12de <t1+0x16e>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d05(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1050 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
jmp    137b <t1+0x20b>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xd35(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    131e <t1+0x1ae>
mov    -0x14(%rbp),%edi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1060 <lockf@plt>
mov    %eax,-0x1c(%rbp)
jmp    1376 <t1+0x206>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xcf8(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1359 <t1+0x1e9>
mov    -0x14(%rbp),%edi
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
call   1090 <flock@plt>
mov    %eax,-0x1c(%rbp)
jmp    1371 <t1+0x201>
mov    $0x0,%al
call   1030 <t1_usage@plt>
mov    0x2c49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13e4 <t1+0x274>
jmp    1376 <t1+0x206>
jmp    137b <t1+0x20b>
cmpl   $0x0,-0x18(%rbp)
je     13b7 <t1+0x247>
cmpl   $0x0,-0x1c(%rbp)
jne    13a0 <t1+0x230>
mov    0x2c12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    13ac <t1+0x23c>
mov    0x2c09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13e4 <t1+0x274>
cmpl   $0x0,-0x1c(%rbp)
jne    13d2 <t1+0x262>
mov    0x2be8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
jmp    13de <t1+0x26e>
mov    0x2bcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<t1>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
cmp    $0x5,%edi
jne    11b5 <t1+0x45>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xe75(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
mov    %eax,%r14d
test   %eax,%eax
je     11ce <t1+0x5e>
mov    0x10(%rbx),%rdi
lea    0xe5c(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     11ce <t1+0x5e>
xor    %eax,%eax
call   1030 <t1_usage@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x20(%rbx),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     124f <t1+0xdf>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     126d <t1+0xfd>
mov    0x18(%rbx),%rdi
lea    0xe18(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12bc <t1+0x14c>
mov    0x18(%rbx),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
jne    11b5 <t1+0x45>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1090 <flock@plt>
test   %r14d,%r14d
jne    12b2 <t1+0x142>
jmp    12d6 <t1+0x166>
mov    0x2d6a(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rbx),%rdx
lea    0xda4(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11bc <t1+0x4c>
mov    0x2d24(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2d37(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <fcntl@plt>
test   %r14d,%r14d
je     12d6 <t1+0x166>
test   %eax,%eax
je     11bc <t1+0x4c>
jmp    12de <t1+0x16e>
mov    0x2d15(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    $0x1,%edx
call   1060 <lockf@plt>
test   %r14d,%r14d
jne    12b2 <t1+0x142>
test   %eax,%eax
jne    11bc <t1+0x4c>
mov    0x2cc3(%rip),%rax
jmp    11c3 <t1+0x53>

LLVM IR (-O0):
%struct.flock = type { i32, i64, i32, i32 }
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"off\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.3 = [3 x i8] c"-c\00"
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.4 = [3 x i8] c"-l\00"
@F_LOCK = global i32 0
@.str.5 = [3 x i8] c"-f\00"
@LOCK_EX = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @t1(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.flock
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 5
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (...) @t1_usage()
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %3
br label %109
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @strncmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %15
store i32 1, i32* %7
br label %33
22: ; preds = %15
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strncmp(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %22
store i32 0, i32* %7
br label %32
29: ; preds = %22
%30 = call i32 (...) @t1_usage()
%31 = load i32, i32* @EXIT_FAILURE
store i32 %31, i32* %3
br label %109
32: ; preds = %28
br label %33
33: ; preds = %32, %21
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 4
%36 = load i8*, i8** %35
%37 = load i32, i32* @O_RDWR
%38 = call i32 @open(i8* %36, i32 %37)
store i32 %38, i32* %6
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %109
47: ; preds = %33
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = call i32 @strncmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 3)
%52 = icmp ne i32 %51, 0
br i1 %52, label %63, label %53
53: ; preds = %47
%54 = load i32, i32* @F_RDLCK
%55 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 3
store i32 %54, i32* %55
%56 = load i32, i32* @SEEK_SET
%57 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 2
store i32 %56, i32* %57
%58 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 1
store i64 0, i64* %58
%59 = getelementptr inbounds %struct.flock, %struct.flock* %9, i32 0, i32 0
store i32 1, i32* %59
%60 = load i32, i32* %6
%61 = load i32, i32* @F_SETLK
%62 = call i32 @fcntl(i32 %60, i32 %61, %struct.flock* %9)
store i32 %62, i32* %8
br label %88
63: ; preds = %47
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 3
%66 = load i8*, i8** %65
%67 = call i32 @strncmp(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 3)
%68 = icmp ne i32 %67, 0
br i1 %68, label %73, label %69
69: ; preds = %63
%70 = load i32, i32* %6
%71 = load i32, i32* @F_LOCK
%72 = call i32 @lockf(i32 %70, i32 %71, i32 1)
store i32 %72, i32* %8
br label %87
73: ; preds = %63
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 3
%76 = load i8*, i8** %75
%77 = call i32 @strncmp(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 3)
%78 = icmp ne i32 %77, 0
br i1 %78, label %83, label %79
79: ; preds = %73
%80 = load i32, i32* %6
%81 = load i32, i32* @LOCK_EX
%82 = call i32 @flock(i32 %80, i32 %81)
store i32 %82, i32* %8
br label %86
83: ; preds = %73
%84 = call i32 (...) @t1_usage()
%85 = load i32, i32* @EXIT_FAILURE
store i32 %85, i32* %3
br label %109
86: ; preds = %79
br label %87
87: ; preds = %86, %69
br label %88
88: ; preds = %87, %53
%89 = load i32, i32* %7
%90 = icmp ne i32 %89, 0
br i1 %90, label %91, label %100
91: ; preds = %88
%92 = load i32, i32* %8
%93 = icmp eq i32 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %91
%95 = load i32, i32* @EXIT_SUCCESS
br label %98
96: ; preds = %91
%97 = load i32, i32* @EXIT_FAILURE
br label %98
98: ; preds = %96, %94
%99 = phi i32 [ %95, %94 ], [ %97, %96 ]
store i32 %99, i32* %3
br label %109
100: ; preds = %88
%101 = load i32, i32* %8
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %100
%104 = load i32, i32* @EXIT_FAILURE
br label %107
105: ; preds = %100
%106 = load i32, i32* @EXIT_SUCCESS
br label %107
107: ; preds = %105, %103
%108 = phi i32 [ %104, %103 ], [ %106, %105 ]
store i32 %108, i32* %3
br label %109
109: ; preds = %107, %98, %83, %40, %29, %12
%110 = load i32, i32* %3
ret i32 %110
}

LLVM IR (-O2):
%struct.flock = type { i32, i64, i32, i32 }
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"on\00"
@.str.1 = [4 x i8] c"off\00"
@O_RDWR = global i32 0
@stderr = global i32 0
@.str.2 = [24 x i8] c"Couldn't open file: %s\0A\00"
@.str.3 = [3 x i8] c"-c\00"
@F_RDLCK = global i32 0
@SEEK_SET = global i32 0
@F_SETLK = global i32 0
@.str.4 = [3 x i8] c"-l\00"
@F_LOCK = global i32 0
@.str.5 = [3 x i8] c"-f\00"
@LOCK_EX = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @t1(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.flock
%4 = icmp eq i32 %0, 5
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 (...) @t1_usage()
%7 = load i32, i32* @EXIT_FAILURE
br label %75
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @strncmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %8
%14 = load i8*, i8** %9
%15 = tail call i32 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 (...) @t1_usage()
%19 = load i32, i32* @EXIT_FAILURE
br label %75
20: ; preds = %13, %8
%21 = getelementptr inbounds i8*, i8** %1, i64 4
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDWR
%24 = tail call i32 @open(i8* %22, i32 %23)
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @EXIT_FAILURE
br label %75
32: ; preds = %20
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = tail call i32 @strncmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 3)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = bitcast %struct.flock* %3 to i8*
%39 = load i32, i32* @F_RDLCK
%40 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 3
store i32 %39, i32* %40
%41 = load i32, i32* @SEEK_SET
%42 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 2
store i32 %41, i32* %42
%43 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 1
store i64 0, i64* %43
%44 = getelementptr inbounds %struct.flock, %struct.flock* %3, i64 0, i32 0
store i32 1, i32* %44
%45 = load i32, i32* @F_SETLK
%46 = call i32 @fcntl(i32 %24, i32 %45, %struct.flock* %3)
br label %64
47: ; preds = %32
%48 = load i8*, i8** %33
%49 = tail call i32 @strncmp(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 3)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* @F_LOCK
%53 = tail call i32 @lockf(i32 %24, i32 %52, i32 1)
br label %64
54: ; preds = %47
%55 = load i8*, i8** %33
%56 = tail call i32 @strncmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 3)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i32, i32* @LOCK_EX
%60 = tail call i32 @flock(i32 %24, i32 %59)
br label %64
61: ; preds = %54
%62 = tail call i32 (...) @t1_usage()
%63 = load i32, i32* @EXIT_FAILURE
br label %75
64: ; preds = %51, %58, %37
%65 = phi i32 [ %60, %58 ], [ %53, %51 ], [ %46, %37 ]
%66 = icmp eq i32 %65, 0
br i1 %12, label %67, label %71
67: ; preds = %64
%68 = load i32, i32* @EXIT_SUCCESS
%69 = load i32, i32* @EXIT_FAILURE
%70 = select i1 %66, i32 %68, i32 %69
br label %75
71: ; preds = %64
%72 = load i32, i32* @EXIT_FAILURE
%73 = load i32, i32* @EXIT_SUCCESS
%74 = select i1 %66, i32 %72, i32 %73
br label %75
75: ; preds = %71, %67, %61, %26, %17, %5
%76 = phi i32 [ %7, %5 ], [ %19, %17 ], [ %31, %26 ], [ %63, %61 ], [ %70, %67 ], [ %74, %71 ]
ret i32 %76
}