#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 */
unsigned int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ avg_chunksize();
int /*<<< orphan*/ close_database();
int /*<<< orphan*/ get_chunksize_distribution(unsigned int, unsigned int);
int getopt_long(int, char **, char *, int /*<<< orphan*/ *,
                int /*<<< orphan*/ *);
int /*<<< orphan*/ open_database();
int /*<<< orphan*/ optarg;
int main(int argc, char *argv[]) {
  int opt = 0;
  unsigned int lb = 1, rb = -1;
  int distribution = 0;
  while ((opt = getopt_long(argc, argv, "l:r:d", NULL, NULL)) != -1) {
    switch (opt) {
    case 'l':
      lb = atoi(optarg);
      break;
    case 'r':
      rb = atoi(optarg);
      break;
    case 'd':
      distribution = 1;
      break;
    default:
      return -1;
    }
  }
  open_database();
  if (distribution)
    get_chunksize_distribution(lb, rb);
  else
    avg_chunksize();
  close_database();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe60(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1040 <getopt_long@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1238 <main+0xd8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x64,%eax
je     121b <main+0xbb>
jmp    11cd <main+0x6d>
mov    -0x24(%rbp),%eax
sub    $0x6c,%eax
je     11ef <main+0x8f>
jmp    11de <main+0x7e>
mov    -0x24(%rbp),%eax
sub    $0x72,%eax
je     1205 <main+0xa5>
jmp    1227 <main+0xc7>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
jmp    1233 <main+0xd3>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1233 <main+0xd3>
movl   $0x1,-0x20(%rbp)
jmp    1233 <main+0xd3>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <main+0x10e>
jmp    1192 <main+0x32>
mov    $0x0,%al
call   1080 <open_database@plt>
cmpl   $0x0,-0x20(%rbp)
je     1259 <main+0xf9>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <get_chunksize_distribution@plt>
jmp    1260 <main+0x100>
mov    $0x0,%al
call   1030 <avg_chunksize@plt>
mov    $0x0,%al
call   1050 <close_database@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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,%r13
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0xffffffff,%r14d
mov    $0x1,%r15d
lea    0xe7b(%rip),%r12
mov    %ebx,%ecx
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <getopt_long@plt>
mov    $0x1,%ecx
cmp    $0x64,%eax
je     1190 <main+0x30>
cmp    $0xffffffff,%eax
je     11e3 <main+0x83>
cmp    $0x72,%eax
je     11d0 <main+0x70>
cmp    $0x6c,%eax
jne    11fb <main+0x9b>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,%r15d
jmp    1185 <main+0x25>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,%r14d
jmp    1185 <main+0x25>
xor    %eax,%eax
call   1080 <open_database@plt>
test   %ebx,%ebx
je     1202 <main+0xa2>
mov    %r15d,%edi
mov    %r14d,%esi
call   1060 <get_chunksize_distribution@plt>
jmp    1209 <main+0xa9>
mov    $0xffffffff,%ebx
jmp    1212 <main+0xb2>
xor    %eax,%eax
call   1030 <avg_chunksize@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <close_database@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"l:r:d\00"
@optarg = global i32 0
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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 1, i32* %7
store i32 -1, i32* %8
store i32 0, i32* %9
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt_long(i32 %11, i8** %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %26
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %24 [
i32 108, label %17
i32 114, label %20
i32 100, label %23
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = call i32 @atoi(i32 %18)
store i32 %19, i32* %7
br label %25
20: ; preds = %15
%21 = load i32, i32* @optarg
%22 = call i32 @atoi(i32 %21)
store i32 %22, i32* %8
br label %25
23: ; preds = %15
store i32 1, i32* %9
br label %25
24: ; preds = %15
store i32 -1, i32* %3
br label %38
25: ; preds = %23, %20, %17
br label %10
26: ; preds = %10
%27 = call i32 (...) @open_database()
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 @get_chunksize_distribution(i32 %31, i32 %32)
br label %36
34: ; preds = %26
%35 = call i32 (...) @avg_chunksize()
br label %36
36: ; preds = %34, %30
%37 = call i32 (...) @close_database()
store i32 0, i32* %3
br label %38
38: ; preds = %36, %24
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str = [6 x i8] c"l:r:d\00"
@optarg = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %13, %2
%4 = phi i32 [ %15, %13 ], [ 1, %2 ]
%5 = phi i32 [ %8, %13 ], [ -1, %2 ]
%6 = phi i32 [ %11, %13 ], [ 0, %2 ]
br label %7
7: ; preds = %3, %16
%8 = phi i32 [ %5, %3 ], [ %18, %16 ]
%9 = phi i32 [ %6, %3 ], [ %11, %16 ]
br label %10
10: ; preds = %7, %10
%11 = phi i32 [ 1, %10 ], [ %9, %7 ]
%12 = tail call i32 @getopt_long(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* null, i32* null)
switch i32 %12, label %28 [
i32 -1, label %19
i32 108, label %13
i32 114, label %16
i32 100, label %10
]
13: ; preds = %10
%14 = load i32, i32* @optarg
%15 = tail call i32 @atoi(i32 %14)
br label %3
16: ; preds = %10
%17 = load i32, i32* @optarg
%18 = tail call i32 @atoi(i32 %17)
br label %7
19: ; preds = %10
%20 = tail call i32 (...) @open_database()
%21 = icmp eq i32 %11, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @get_chunksize_distribution(i32 %4, i32 %8)
br label %26
24: ; preds = %19
%25 = tail call i32 (...) @avg_chunksize()
br label %26
26: ; preds = %24, %22
%27 = tail call i32 (...) @close_database()
br label %28
28: ; preds = %10, %26
%29 = phi i32 [ 0, %26 ], [ -1, %10 ]
ret i32 %29
}