#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 *);
scalar_t__ balloon_init(int *);
int balloon_op(int *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char *);
int main(int argc, char *argv[]) {
  int fd;
  int r;
  int bytes;
  if (argc != 3) {
    perror("Please provide op=[i|d], bytes\n");
    return 1;
  }
  bytes = atoi(argv[2]);
  switch (*argv[1]) {
  case 'i':
    break;
  case 'd':
    bytes = -bytes;
    break;
  default:
    perror("Wrong op param\n");
    return 1;
  }
  if (balloon_init(&fd)) {
    perror("balloon_init failed\n");
    return 1;
  }
  if ((r = balloon_op(&fd, bytes))) {
    perror("balloon_op failed\n");
    goto out;
  }
out:
  close(fd);
  return r;
}


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     1188 <main+0x38>
lea    0xe89(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0x106>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x64,%eax
je     11ca <main+0x7a>
jmp    11b4 <main+0x64>
mov    -0x20(%rbp),%eax
sub    $0x69,%eax
jne    11d7 <main+0x87>
jmp    11c5 <main+0x75>
jmp    11ef <main+0x9f>
xor    %eax,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11ef <main+0x9f>
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0x106>
lea    -0x14(%rbp),%rdi
call   1050 <balloon_init@plt>
cmp    $0x0,%rax
je     121a <main+0xca>
lea    0xe27(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1256 <main+0x106>
mov    -0x1c(%rbp),%esi
lea    -0x14(%rbp),%rdi
call   1030 <balloon_op@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     1243 <main+0xf3>
lea    0xe0c(%rip),%rdi
call   1060 <perror@plt>
jmp    1248 <main+0xf8>
jmp    1248 <main+0xf8>
mov    -0x14(%rbp),%edi
call   1040 <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   %rbx
push   %rax
cmp    $0x3,%edi
jne    11ac <main+0x5c>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rax
movsbl (%rax),%eax
cmp    $0x69,%eax
je     1179 <main+0x29>
cmp    $0x64,%eax
jne    11cc <main+0x7c>
neg    %ebp
lea    0x4(%rsp),%rdi
call   1050 <balloon_init@plt>
test   %rax,%rax
jne    11b5 <main+0x65>
lea    0x4(%rsp),%rdi
mov    %ebp,%esi
call   1030 <balloon_op@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    11be <main+0x6e>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe4d(%rip),%rdi
jmp    11d3 <main+0x83>
lea    0xe74(%rip),%rdi
jmp    11d3 <main+0x83>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
jmp    119a <main+0x4a>
lea    0xe4d(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%ebx
jmp    11a3 <main+0x53>

LLVM IR (-O0):
@.str = [32 x i8] c"Please provide op=[i|d], bytes\0A\00"
@.str.1 = [16 x i8] c"Wrong op param\0A\00"
@.str.2 = [21 x i8] c"balloon_init failed\0A\00"
@.str.3 = [19 x i8] c"balloon_op failed\0A\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* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %45
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %8
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %27 [
i32 105, label %23
i32 100, label %24
]
23: ; preds = %13
br label %29
24: ; preds = %13
%25 = load i32, i32* %8
%26 = sub nsw i32 0, %25
store i32 %26, i32* %8
br label %29
27: ; preds = %13
%28 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %45
29: ; preds = %24, %23
%30 = call i64 @balloon_init(i32* %6)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %45
34: ; preds = %29
%35 = load i32, i32* %8
%36 = call i32 @balloon_op(i32* %6, i32 %35)
store i32 %36, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %41
40: ; preds = %34
br label %41
41: ; preds = %40, %38
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
%44 = load i32, i32* %7
store i32 %44, i32* %3
br label %45
45: ; preds = %41, %32, %27, %11
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@.str = [32 x i8] c"Please provide op=[i|d], bytes\0A\00"
@.str.1 = [16 x i8] c"Wrong op param\0A\00"
@.str.2 = [21 x i8] c"balloon_init failed\0A\00"
@.str.3 = [19 x i8] c"balloon_op failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %34
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %18 [
i32 105, label %20
i32 100, label %16
]
16: ; preds = %8
%17 = sub nsw i32 0, %11
br label %20
18: ; preds = %8
%19 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %34
20: ; preds = %16, %8
%21 = phi i32 [ %17, %16 ], [ %11, %8 ]
%22 = call i64 @balloon_init(i32* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %34
26: ; preds = %20
%27 = call i32 @balloon_op(i32* %3, i32 %21)
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %26, %29
%32 = load i32, i32* %3
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %31, %24, %18, %6
%35 = phi i32 [ 1, %6 ], [ 1, %18 ], [ 1, %24 ], [ %27, %31 ]
ret i32 %35
}