#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 EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int print_size(int);
int set_size(int, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int vsd, ret = EXIT_FAILURE;
  if (argc > 3 || argc < 2) {
    usage(argv[0]);
    return EXIT_FAILURE;
  }
  vsd = open("/dev/vsd", O_RDONLY);
  if (vsd == -1) {
    perror("open");
    goto exit;
  }
  if (!strcmp("size_get", argv[1]))
    ret = print_size(vsd);
  else if (!strcmp("size_set", argv[1])) {
    if (argc != 3) {
      usage(argv[0]);
      goto err;
    }
    int size = atoi(argv[2]);
    if (size <= 0) {
      usage(argv[0]);
      goto err;
    }
    ret = set_size(vsd, size);
  } else {
    usage(argv[0]);
    goto err;
  }
err:
  close(vsd);
exit:
  return ret;
}


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)
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jg     11b6 <main+0x36>
cmpl   $0x2,-0x8(%rbp)
jge    11d3 <main+0x53>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d2 <main+0x152>
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1206 <main+0x86>
lea    0xe0d(%rip),%rdi
call   1090 <perror@plt>
jmp    12cc <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdf9(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1233 <main+0xb3>
mov    -0x14(%rbp),%edi
call   1030 <print_size@plt>
mov    %eax,-0x18(%rbp)
jmp    12bf <main+0x13f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdd5(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    12a9 <main+0x129>
cmpl   $0x3,-0x8(%rbp)
je     126b <main+0xeb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    12c4 <main+0x144>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1296 <main+0x116>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    12c4 <main+0x144>
mov    -0x14(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1040 <set_size@plt>
mov    %eax,-0x18(%rbp)
jmp    12ba <main+0x13a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    12c4 <main+0x144>
jmp    12bf <main+0x13f>
jmp    12c4 <main+0x144>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %edi,%ebx
mov    0x2e44(%rip),%rbp
lea    -0x4(%rbx),%eax
cmp    $0xfffffffd,%eax
ja     11ae <main+0x2e>
mov    (%r12),%rdi
call   1070 <usage@plt>
mov    0x0(%rbp),%r15d
jmp    1237 <main+0xb7>
mov    0x0(%rbp),%r15d
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1243 <main+0xc3>
mov    %eax,%r14d
mov    0x8(%r12),%rbp
lea    0xe33(%rip),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
je     1224 <main+0xa4>
lea    0xe29(%rip),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    1219 <main+0x99>
cmp    $0x3,%ebx
jne    1219 <main+0x99>
mov    0x10(%r12),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
jle    1219 <main+0x99>
mov    %r14d,%edi
mov    %eax,%esi
call   1040 <set_size@plt>
jmp    122c <main+0xac>
mov    (%r12),%rdi
call   1070 <usage@plt>
jmp    122f <main+0xaf>
mov    %r14d,%edi
call   1030 <print_size@plt>
mov    %eax,%r15d
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbf(%rip),%rdi
call   1090 <perror@plt>
jmp    1237 <main+0xb7>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [9 x i8] c"/dev/vsd\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [9 x i8] c"size_get\00"
@.str.3 = [9 x i8] c"size_set\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @EXIT_FAILURE
store i32 %9, i32* %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 3
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %12, %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %3
br label %79
21: ; preds = %12
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %77
28: ; preds = %21
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %28
%35 = load i32, i32* %6
%36 = call i32 @print_size(i32 %35)
store i32 %36, i32* %7
br label %73
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @strcmp(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %67, label %43
43: ; preds = %37
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 3
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @usage(i8* %49)
br label %74
51: ; preds = %43
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %8
%56 = load i32, i32* %8
%57 = icmp sle i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %51
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i32 @usage(i8* %61)
br label %74
63: ; preds = %51
%64 = load i32, i32* %6
%65 = load i32, i32* %8
%66 = call i32 @set_size(i32 %64, i32 %65)
store i32 %66, i32* %7
br label %72
67: ; preds = %37
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = call i32 @usage(i8* %70)
br label %74
72: ; preds = %63
br label %73
73: ; preds = %72, %34
br label %74
74: ; preds = %73, %67, %58, %46
%75 = load i32, i32* %6
%76 = call i32 @close(i32 %75)
br label %77
77: ; preds = %74, %26
%78 = load i32, i32* %7
store i32 %78, i32* %3
br label %79
79: ; preds = %77, %15
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [9 x i8] c"/dev/vsd\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [9 x i8] c"size_get\00"
@.str.3 = [9 x i8] c"size_set\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @EXIT_FAILURE
%4 = add i32 %0, -4
%5 = icmp ult i32 %4, -2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
br label %47
10: ; preds = %2
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %47
16: ; preds = %10
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @strcmp(i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* dereferenceable(1) %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @print_size(i32 %12)
br label %44
23: ; preds = %16
%24 = tail call i32 @strcmp(i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* dereferenceable(1) %18)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %23
%27 = icmp eq i32 %0, 3
br i1 %27, label %31, label %28
28: ; preds = %26
%29 = load i8*, i8** %1
%30 = tail call i32 @usage(i8* %29)
br label %44
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = tail call i32 @atoi(i8* %33)
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = load i8*, i8** %1
%38 = tail call i32 @usage(i8* %37)
br label %44
39: ; preds = %31
%40 = tail call i32 @set_size(i32 %12, i32 %34)
br label %44
41: ; preds = %23
%42 = load i8*, i8** %1
%43 = tail call i32 @usage(i8* %42)
br label %44
44: ; preds = %39, %36, %21, %41, %28
%45 = phi i32 [ %3, %41 ], [ %3, %28 ], [ %22, %21 ], [ %3, %36 ], [ %40, %39 ]
%46 = tail call i32 @close(i32 %12)
br label %47
47: ; preds = %14, %44, %6
%48 = phi i32 [ %9, %6 ], [ %3, %14 ], [ %45, %44 ]
ret i32 %48
}