#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 */
typedef int /*<<< orphan*/ pthread_spinlock_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int, int, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
char *strdup(char *);
int main(int argc, char **argv) {
  pthread_spinlock_t *sl1;
  int rv, fd;
  int *count;
  short rv_short;
  int i, x = 0;
  void *map_region;
  char *file;
  if (argc != 2) {
    fprintf(stderr, "USAGE: guestlock <file>\n");
    exit(-1);
  }
  file = strdup(argv[1]);
  if ((fd = open(file, O_RDWR)) < 0) {
    fprintf(stderr, "ERROR: cannot open file\n");
    exit(-1);
  }
  printf("[SENDIOCTL] sending ioctl to %s\n", file);
  rv = ioctl(fd, 2, NULL);
  printf("[SENDIOCTL] rv is %d\n", rv);
  close(fd);
  printf("[SENDIOCTL] exiting\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     11af <main+0x3f>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11fd <main+0x8d>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x48(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11f8 <main+0x78>
mov    0x8(%rsi),%rdi
call   10a0 <strdup@plt>
mov    %rax,%r14
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
test   %eax,%eax
js     120a <main+0x8a>
mov    %eax,%ebx
lea    0xe7f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xe80(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
jmp    121a <main+0x9a>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"USAGE: guestlock <file>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [25 x i8] c"ERROR: cannot open file\0A\00"
@.str.2 = [33 x i8] c"[SENDIOCTL] sending ioctl to %s\0A\00"
@.str.3 = [22 x i8] c"[SENDIOCTL] rv is %d\0A\00"
@.str.4 = [21 x i8] c"[SENDIOCTL] exiting\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i16
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %11
%14 = load i32, i32* %3
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %13
%25 = load i8*, i8** %13
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 -1)
unreachable
33: ; preds = %20
%34 = load i8*, i8** %13
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = load i32, i32* %7
%37 = call i32 @ioctl(i32 %36, i32 2, i32* null)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"USAGE: guestlock <file>\0A\00"
@O_RDWR = global i32 0
@.str.1 = [25 x i8] c"ERROR: cannot open file\0A\00"
@.str.2 = [33 x i8] c"[SENDIOCTL] sending ioctl to %s\0A\00"
@.str.3 = [22 x i8] c"[SENDIOCTL] rv is %d\0A\00"
@str = [20 x i8] c"[SENDIOCTL] exiting\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i8* @strdup(i8* %10)
%12 = load i32, i32* @O_RDWR
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %8
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%21 = tail call i32 @ioctl(i32 %13, i32 2, i32* null)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = tail call i32 @close(i32 %13)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
ret i32 0
}