#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ int16_t;
typedef int /*<<< orphan*/ dist_data;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ generate_latencies(int /*<<< orphan*/ *, size_t,
                                      int /*<<< orphan*/, int /*<<< orphan*/,
                                      int /*<<< orphan*/, int);
size_t get_distribution(char *, int /*<<< orphan*/ *, int);
scalar_t__ get_stats(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                     int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    printf("Usage: le <dist_table_file> <number_of_samples>\n");
    exit(2);
  }
  char *dist_file = argv[1];
  int count = atoi(argv[2]);
  uint32_t mu, sigma, rho;
  if (get_stats(dist_file, &mu, &sigma, &rho) != 0) {
    fprintf(stderr, "Failed to parse stats from %s", dist_file);
    exit(3);
  }
  int16_t *dist_data = NULL;
  size_t dist_size = 0;
  dist_data = calloc(sizeof(dist_data[0]), (16 * 1024));
  dist_size = get_distribution(dist_file, dist_data, (16 * 1024));
  if (dist_size <= 0) {
    fprintf(stderr, "Failed to parse distribution table from %s\n", dist_file);
    exit(3);
  }
  generate_latencies(dist_data, dist_size, mu, sigma, rho, count);
  return 0;
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11b6 <main+0x36>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <get_stats@plt>
cmp    $0x0,%rax
je     1214 <main+0x94>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x4,%edi
mov    $0x4000,%esi
call   1060 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x4000,%edx
call   1040 <get_distribution@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
ja     127b <main+0xfb>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x1c(%rbp),%r9d
call   1030 <generate_latencies@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    1206 <main+0x86>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1080 <get_stats@plt>
test   %rax,%rax
jne    121c <main+0x9c>
mov    $0x4,%edi
mov    $0x4000,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
mov    $0x4000,%edx
call   1050 <get_distribution@plt>
test   %rax,%rax
je     122e <main+0xae>
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r14d,%r9d
call   1030 <generate_latencies@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
jmp    123e <main+0xbe>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"Usage: le <dist_table_file> <number_of_samples>\0A\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Failed to parse stats from %s\00"
@.str.2 = [44 x i8] c"Failed to parse distribution table from %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8*, i8** %6
%27 = call i64 @get_stats(i8* %26, i32* %8, i32* %9, i32* %10)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %18
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %31)
%33 = call i32 @exit(i32 3)
unreachable
34: ; preds = %18
store i32* null, i32** %11
store i64 0, i64* %12
%35 = call i32* @calloc(i32 4, i32 16384)
store i32* %35, i32** %11
%36 = load i8*, i8** %6
%37 = load i32*, i32** %11
%38 = call i64 @get_distribution(i8* %36, i32* %37, i32 16384)
store i64 %38, i64* %12
%39 = load i64, i64* %12
%40 = icmp ule i64 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %34
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %6
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %43)
%45 = call i32 @exit(i32 3)
unreachable
46: ; preds = %34
%47 = load i32*, i32** %11
%48 = load i64, i64* %12
%49 = load i32, i32* %8
%50 = load i32, i32* %9
%51 = load i32, i32* %10
%52 = load i32, i32* %7
%53 = call i32 @generate_latencies(i32* %47, i64 %48, i32 %49, i32 %50, i32 %51, i32 %52)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.1 = [30 x i8] c"Failed to parse stats from %s\00"
@.str.2 = [44 x i8] c"Failed to parse distribution table from %s\0A\00"
@str = [48 x i8] c"Usage: le <dist_table_file> <number_of_samples>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 3
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 2)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = bitcast i32* %3 to i8*
%17 = bitcast i32* %4 to i8*
%18 = bitcast i32* %5 to i8*
%19 = call i64 @get_stats(i8* %12, i32* %3, i32* %4, i32* %5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %25, label %21
21: ; preds = %10
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%24 = call i32 @exit(i32 3)
unreachable
25: ; preds = %10
%26 = call i32* @calloc(i32 4, i32 16384)
%27 = call i64 @get_distribution(i8* %12, i32* %26, i32 16384)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%32 = call i32 @exit(i32 3)
unreachable
33: ; preds = %25
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = call i32 @generate_latencies(i32* %26, i64 %27, i32 %34, i32 %35, i32 %36, i32 %15)
ret i32 0
}