#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 */
struct option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ *member_2;
  int /*<<< orphan*/ const member_1;
};
struct disk_info {
  int dummy;
};

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *basename(char *const);
int /*<<< orphan*/ close_disk_info(struct disk_info *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt_long(int const, char *const *, char *, struct option const *,
                int /*<<< orphan*/ *);
scalar_t__ handle_device(struct disk_info *, unsigned int);
struct disk_info *init_disk_info(char *const);
#define no_argument 128
int const optind;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(const int argc, char *const *argv) {
  int retcode = EXIT_SUCCESS;
  struct disk_info *node = NULL;
  int i;
  unsigned int exit_after_getopt;
  unsigned int want_export;
  static const struct option const long_options[] = {
      {"export", no_argument, NULL, 'x'},
      {"help", no_argument, NULL, 'h'},
      {0}};
  exit_after_getopt = 0;
  want_export = 0;
  while ((i = getopt_long(argc, argv, "xh", long_options, NULL)) != -1) {
    switch (i) {
    case 'h':
      fprintf(stdout,
              ("Usage: %s [-h] [-x] <DEVICE>\n"
               "  -h, --help           print this help message and exit\n"
               "  -x, --export         print environment variables\n"
               "\n"),
              basename(argv[0]));
      exit_after_getopt = 1;
      break;
    case 'x':
      want_export = 1;
      break;
    default:
      retcode = EXIT_FAILURE;
      exit_after_getopt = 1;
    }
  }
  if (exit_after_getopt == 0) {
    if (optind < argc) {
      node = init_disk_info(argv[optind]);
      if (node == NULL) {
        fprintf(stderr, "failed to open device '%s'\n", argv[i]);
        retcode = EXIT_FAILURE;
      } else if (handle_device(node, want_export) != 0) {
        retcode = EXIT_FAILURE;
      }
    } else {
      fprintf(stderr, "no device specified\n");
      retcode = EXIT_FAILURE;
    }
  }
  fflush(stdout);
  fflush(stderr);
  if (node != NULL) {
    close_disk_info(node);
    node = NULL;
  }
  return retcode;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdx
lea    0x2bd3(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1040 <getopt_long@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1254 <main+0xe4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x68,%eax
je     11f8 <main+0x88>
jmp    11e7 <main+0x77>
mov    -0x30(%rbp),%eax
sub    $0x78,%eax
je     1230 <main+0xc0>
jmp    123c <main+0xcc>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <basename@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x28(%rbp)
jmp    124f <main+0xdf>
movl   $0x1,-0x2c(%rbp)
jmp    124f <main+0xdf>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    11a8 <main+0x38>
cmpl   $0x0,-0x28(%rbp)
jne    131e <main+0x1ae>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    12f6 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x2d65(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <init_disk_info@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12ca <main+0x15a>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xde7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12f1 <main+0x181>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1070 <handle_device@plt>
cmp    $0x0,%rax
je     12ec <main+0x17c>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    12f1 <main+0x181>
jmp    1319 <main+0x1a9>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
jmp    131e <main+0x1ae>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
cmpq   $0x0,-0x20(%rbp)
je     1356 <main+0x1e6>
mov    -0x20(%rbp),%rdi
call   1030 <close_disk_info@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebx
mov    0x2e41(%rip),%rax
lea    0xe7e(%rip),%r12
lea    0x2c0b(%rip),%r13
xor    %r14d,%r14d
xor    %ebp,%ebp
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %ebp,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r8d,%r8d
call   1040 <getopt_long@plt>
mov    $0x1,%ecx
cmp    $0x78,%eax
je     11b0 <main+0x40>
cmp    $0xffffffff,%eax
je     1222 <main+0xb2>
cmp    $0x68,%eax
jne    1210 <main+0xa0>
mov    0x2df0(%rip),%rax
mov    (%rax),%r14d
mov    (%r15),%rdi
call   1060 <basename@plt>
mov    %r14d,%edi
lea    0xe1a(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r14d
jmp    11a0 <main+0x30>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%r14d
mov    0x2dbb(%rip),%rax
jmp    119a <main+0x2a>
test   %r14d,%r14d
je     122f <main+0xbf>
xor    %ebx,%ebx
mov    0x4(%rsp),%ebp
jmp    1299 <main+0x129>
test   %ebx,%ebx
jle    1258 <main+0xe8>
mov    (%r15),%rdi
call   1090 <init_disk_info@plt>
test   %rax,%rax
je     1273 <main+0x103>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1070 <handle_device@plt>
test   %rax,%rax
mov    0x4(%rsp),%ebp
jne    1290 <main+0x120>
jmp    1299 <main+0x129>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1290 <main+0x120>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%r15),%rdx
lea    0xe12(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%ebp
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
test   %rbx,%rbx
je     12c2 <main+0x152>
mov    %rbx,%rdi
call   1030 <close_disk_info@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.disk_info = type { i32 }
@EXIT_SUCCESS = global i32 0
@main.long_options = internal constant [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 120 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"export\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [3 x i8] c"xh\00"
@stdout = global i32 0
@.str.3 = [138 x i8] c"Usage: %s [-h] [-x] <DEVICE>\0A -h, --help print this help message and exit\0A -x, --export print environment variables\0A\0A\00"
@EXIT_FAILURE = global i32 0
@optind = constant i32 0
@stderr = global i32 0
@.str.4 = [28 x i8] c"failed to open device '%s'\0A\00"
@.str.5 = [21 x i8] c"no device specified\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.disk_info*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @EXIT_SUCCESS
store i32 %11, i32* %6
store %struct.disk_info* null, %struct.disk_info** %7
store i32 0, i32* %9
store i32 0, i32* %10
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt_long(i32 %13, i8** %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
store i32 %15, i32* %8
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %30
17: ; preds = %12
%18 = load i32, i32* %8
switch i32 %18, label %27 [
i32 104, label %19
i32 120, label %26
]
19: ; preds = %17
%20 = load i32, i32* @stdout
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i8* @basename(i8* %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i32 1, i32* %9
br label %29
26: ; preds = %17
store i32 1, i32* %10
br label %29
27: ; preds = %17
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %6
store i32 1, i32* %9
br label %29
29: ; preds = %27, %26, %19
br label %12
30: ; preds = %12
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %69
33: ; preds = %30
%34 = load i32, i32* @optind
%35 = load i32, i32* %4
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %64
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i32, i32* @optind
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call %struct.disk_info* @init_disk_info(i8* %42)
store %struct.disk_info* %43, %struct.disk_info** %7
%44 = load %struct.disk_info*, %struct.disk_info** %7
%45 = icmp eq %struct.disk_info* %44, null
br i1 %45, label %46, label %55
46: ; preds = %37
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %6
br label %63
55: ; preds = %37
%56 = load %struct.disk_info*, %struct.disk_info** %7
%57 = load i32, i32* %10
%58 = call i64 @handle_device(%struct.disk_info* %56, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %55
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %6
br label %62
62: ; preds = %60, %55
br label %63
63: ; preds = %62, %46
br label %68
64: ; preds = %33
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32, i32* @EXIT_FAILURE
store i32 %67, i32* %6
br label %68
68: ; preds = %64, %63
br label %69
69: ; preds = %68, %30
%70 = load i32, i32* @stdout
%71 = call i32 @fflush(i32 %70)
%72 = load i32, i32* @stderr
%73 = call i32 @fflush(i32 %72)
%74 = load %struct.disk_info*, %struct.disk_info** %7
%75 = icmp ne %struct.disk_info* %74, null
br i1 %75, label %76, label %79
76: ; preds = %69
%77 = load %struct.disk_info*, %struct.disk_info** %7
%78 = call i32 @close_disk_info(%struct.disk_info* %77)
store %struct.disk_info* null, %struct.disk_info** %7
br label %79
79: ; preds = %76, %69
%80 = load i32, i32* %6
ret i32 %80
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
%struct.disk_info = type { i32 }
@EXIT_SUCCESS = global i32 0
@main.long_options = internal constant [3 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32* null, i32 120 }, %struct.option { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8 -128, i32* null, i32 104 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"export\00"
@.str.1 = [5 x i8] c"help\00"
@.str.2 = [3 x i8] c"xh\00"
@stdout = global i32 0
@.str.3 = [138 x i8] c"Usage: %s [-h] [-x] <DEVICE>\0A -h, --help print this help message and exit\0A -x, --export print environment variables\0A\0A\00"
@EXIT_FAILURE = global i32 0
@optind = constant i32 0
@stderr = global i32 0
@.str.4 = [28 x i8] c"failed to open device '%s'\0A\00"
@.str.5 = [21 x i8] c"no device specified\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %11, %2
%4 = phi i32* [ @EXIT_SUCCESS, %2 ], [ @EXIT_FAILURE, %11 ]
%5 = phi i32 [ 0, %2 ], [ 1, %11 ]
%6 = phi i32 [ 0, %2 ], [ %12, %11 ]
%7 = load i32, i32* %4
br label %8
8: ; preds = %3, %14
%9 = phi i32 [ %5, %3 ], [ 1, %14 ]
%10 = phi i32 [ %6, %3 ], [ %12, %14 ]
br label %11
11: ; preds = %8, %11
%12 = phi i32 [ 1, %11 ], [ %10, %8 ]
%13 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.option* getelementptr inbounds ([3 x %struct.option], [3 x %struct.option]* @main.long_options, i64 0, i64 0), i32* null)
switch i32 %13, label %3 [
i32 -1, label %19
i32 104, label %14
i32 120, label %11
]
14: ; preds = %11
%15 = load i32, i32* @stdout
%16 = load i8*, i8** %1
%17 = tail call i8* @basename(i8* %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %8
19: ; preds = %11
%20 = icmp eq i32 %9, 0
br i1 %20, label %21, label %42
21: ; preds = %19
%22 = icmp sgt i32 %0, 0
br i1 %22, label %23, label %38
23: ; preds = %21
%24 = load i8*, i8** %1
%25 = tail call %struct.disk_info* @init_disk_info(i8* %24)
%26 = icmp eq %struct.disk_info* %25, null
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds i8*, i8** %1, i64 -1
%30 = load i8*, i8** %29
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %42
33: ; preds = %23
%34 = tail call i64 @handle_device(%struct.disk_info* %25, i32 %12)
%35 = icmp eq i64 %34, 0
%36 = load i32, i32* @EXIT_FAILURE
%37 = select i1 %35, i32 %7, i32 %36
br label %42
38: ; preds = %21
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
br label %42
42: ; preds = %33, %38, %27, %19
%43 = phi %struct.disk_info* [ null, %27 ], [ null, %38 ], [ null, %19 ], [ %25, %33 ]
%44 = phi i32 [ %32, %27 ], [ %41, %38 ], [ %7, %19 ], [ %37, %33 ]
%45 = load i32, i32* @stdout
%46 = tail call i32 @fflush(i32 %45)
%47 = load i32, i32* @stderr
%48 = tail call i32 @fflush(i32 %47)
%49 = icmp eq %struct.disk_info* %43, null
br i1 %49, label %52, label %50
50: ; preds = %42
%51 = tail call i32 @close_disk_info(%struct.disk_info* %43)
br label %52
52: ; preds = %50, %42
ret i32 %44
}