#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ ioctl(int, int, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ warn(char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("arg missing\n");
    return 1;
  }
  int f = open("/dev/pcivault", O_RDWR);
  if (f < 0)
    err(1, "open");
  if (ioctl(f, 1, argv[1]) < 0)
    warn("ioctl");
  close(f);
  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   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0xa5>
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe65(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cb <main+0x6b>
mov    $0x1,%edi
lea    0xe55(%rip),%rsi
call   1070 <err@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    $0x1,%esi
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11f6 <main+0x96>
lea    0xe2f(%rip),%rdi
call   1030 <warn@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    11c4 <main+0x64>
mov    %rsi,%r14
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1198 <main+0x38>
lea    0xe80(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x8(%r14),%rdx
mov    %ebx,%edi
mov    $0x1,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11b9 <main+0x59>
lea    0xe5f(%rip),%rdi
call   1030 <warn@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    11d5 <main+0x75>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"arg missing\0A\00"
@.str.1 = [14 x i8] c"/dev/pcivault\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\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, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %30
11: ; preds = %2
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @ioctl(i32 %19, i32 1, i8* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
store i32 0, i32* %3
br label %30
30: ; preds = %27, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"/dev/pcivault\00"
@O_RDWR = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\00"
@str = [12 x i8] c"arg missing\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %21
6: ; preds = %2
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @ioctl(i32 %8, i32 1, i8* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @warn(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = tail call i32 @close(i32 %8)
br label %21
21: ; preds = %19, %4
%22 = phi i32 [ 1, %4 ], [ 0, %19 ]
ret i32 %22
}