#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 */

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ test_filelock(int);
int /*<<< orphan*/ test_pthread_lock(int);
int /*<<< orphan*/ test_semlock(int);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("usage: test_lock file|sem|pthread locktimes/n");
    exit(1);
  }
  int locktimes = atoi(argv[2]);
  if (strcmp(argv[1], "file") == 0)
    test_filelock(locktimes);
  else if (strcmp(argv[1], "sem") == 0)
    test_semlock(locktimes);
  else
    test_pthread_lock(locktimes);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a6 <main+0x36>
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <main+0x71>
mov    -0x14(%rbp),%edi
call   1060 <test_filelock@plt>
jmp    1219 <main+0xa9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe43(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    120c <main+0x9c>
mov    -0x14(%rbp),%edi
call   1050 <test_semlock@plt>
jmp    1214 <main+0xa4>
mov    -0x14(%rbp),%edi
call   1030 <test_pthread_lock@plt>
jmp    1219 <main+0xa9>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    11d0 <main+0x60>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b9 <main+0x49>
mov    0x8(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <strcmp@plt>
mov    %ebp,%edi
test   %rax,%rax
je     11c2 <main+0x52>
call   1030 <test_pthread_lock@plt>
jmp    11c7 <main+0x57>
mov    %ebp,%edi
call   1060 <test_filelock@plt>
jmp    11c7 <main+0x57>
call   1050 <test_semlock@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"usage: test_lock file|sem|pthread locktimes/n\00"
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [4 x i8] c"sem\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 3
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* %6
%24 = call i32 @test_filelock(i32 %23)
br label %38
25: ; preds = %12
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i32, i32* %6
%33 = call i32 @test_semlock(i32 %32)
br label %37
34: ; preds = %25
%35 = load i32, i32* %6
%36 = call i32 @test_pthread_lock(i32 %35)
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %22
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"usage: test_lock file|sem|pthread locktimes/n\00"
@.str.1 = [5 x i8] c"file\00"
@.str.2 = [4 x i8] c"sem\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @test_filelock(i32 %10)
br label %25
17: ; preds = %7
%18 = load i8*, i8** %11
%19 = tail call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @test_semlock(i32 %10)
br label %25
23: ; preds = %17
%24 = tail call i32 @test_pthread_lock(i32 %10)
br label %25
25: ; preds = %21, %23, %15
ret i32 0
}