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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ isalpha(char);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
long strtol(char *, char **, int /*<<< orphan*/);
int get_distribution(const char *name, int16_t *data, int maxdata) {
  FILE *f;
  int n;
  long x;
  size_t len;
  char *line = NULL;
  if ((f = fopen(name, "r")) == NULL) {
    fprintf(stderr, "No distribution data (%s: %s)\n", name, strerror(errno));
    return -1;
  }
  n = 0;
  while (getline(&line, &len, f) != -1) {
    char *p, *endp;
    if (*line == '\n' || *line == '#' || isalpha(*line))
      continue;
    for (p = line;; p = endp) {
      x = strtol(p, &endp, 0);
      if (endp == p)
        break;
      if (n >= maxdata) {
        fprintf(stderr, "%s: too much data\n", name);
        n = -1;
        goto error;
      }
      data[n++] = x;
    }
  }
error:
  free(line);
  fclose(f);
  return n;
}


x86 assembly (clang, -O0):
<get_distribution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ff <get_distribution+0x7f>
mov    0x2e20(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1305 <get_distribution+0x185>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdx
lea    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12e8 <get_distribution+0x168>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1256 <get_distribution+0xd6>
mov    -0x48(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1256 <get_distribution+0xd6>
mov    -0x48(%rbp),%rax
movsbl (%rax),%edi
call   1070 <isalpha@plt>
cmp    $0x0,%rax
je     125b <get_distribution+0xdb>
jmp    1206 <get_distribution+0x86>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    -0x58(%rbp),%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x50(%rbp),%rax
jne    1289 <get_distribution+0x109>
jmp    12e3 <get_distribution+0x163>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     12bc <get_distribution+0x13c>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    12ed <get_distribution+0x16d>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x58(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1263 <get_distribution+0xe3>
jmp    1206 <get_distribution+0x86>
jmp    12ed <get_distribution+0x16d>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_distribution>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
movq   $0x0,(%rsp)
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11ed <get_distribution+0x6d>
mov    %rax,%r15
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     12fd <get_distribution+0x17d>
mov    %r14d,0x1c(%rsp)
mov    %rbx,0x30(%rsp)
mov    %rbp,0x20(%rsp)
xor    %r14d,%r14d
mov    %rsp,%rbp
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r12
jmp    1257 <get_distribution+0xd7>
mov    0x2dec(%rip),%rax
mov    (%rax),%ebx
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xdf7(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    1335 <get_distribution+0x1b5>
lea    0x10(%rsp),%rbx
mov    %r12,%r14
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     1324 <get_distribution+0x1a4>
mov    (%rsp),%rax
mov    (%rax),%al
cmp    $0xa,%al
je     1240 <get_distribution+0xc0>
cmp    $0x23,%al
je     1240 <get_distribution+0xc0>
movsbl %al,%edi
call   1070 <isalpha@plt>
test   %rax,%rax
jne    1240 <get_distribution+0xc0>
mov    %r12,%rsi
mov    %r14,%r12
mov    (%rsp),%r13
mov    %r13,%rdi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%r14
cmp    %r13,%r14
je     1225 <get_distribution+0xa5>
mov    %r12,0x28(%rsp)
movslq %r12d,%rcx
mov    0x1c(%rsp),%edx
cmp    %edx,%ecx
cmovg  %ecx,%edx
movslq %edx,%rbp
sub    %rcx,%rbp
mov    0x30(%rsp),%rdx
lea    (%rdx,%rcx,8),%r13
xor    %ebx,%ebx
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
cmp    %rbx,%rbp
je     1302 <get_distribution+0x182>
mov    %rax,0x0(%r13,%rbx,8)
mov    %r14,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rcx
add    $0x1,%rbx
cmp    %r14,%rcx
mov    %rcx,%r14
jne    12c0 <get_distribution+0x140>
mov    0x28(%rsp),%r14
add    %ebx,%r14d
mov    %rsp,%rbp
lea    0x10(%rsp),%rbx
jmp    1240 <get_distribution+0xc0>
xor    %r14d,%r14d
jmp    1324 <get_distribution+0x1a4>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
mov    0x20(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"No distribution data (%s: %s)\0A\00"
@errno = global i32 0
@.str.2 = [19 x i8] c"%s: too much data\0A\00"
define i32 @get_distribution(i8* %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
store i8* null, i8** %12
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %8
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22)
store i32 -1, i32* %4
br label %79
24: ; preds = %3
store i32 0, i32* %9
br label %25
25: ; preds = %71, %44, %24
%26 = load i32*, i32** %8
%27 = call i32 @getline(i8** %12, i64* %11, i32* %26)
%28 = icmp ne i32 %27, -1
br i1 %28, label %29, label %72
29: ; preds = %25
%30 = load i8*, i8** %12
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %44, label %34
34: ; preds = %29
%35 = load i8*, i8** %12
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 35
br i1 %38, label %44, label %39
39: ; preds = %34
%40 = load i8*, i8** %12
%41 = load i8, i8* %40
%42 = call i64 @isalpha(i8 signext %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39, %34, %29
br label %25
45: ; preds = %39
%46 = load i8*, i8** %12
store i8* %46, i8** %13
br label %47
47: ; preds = %69, %45
%48 = load i8*, i8** %13
%49 = call i64 @strtol(i8* %48, i8** %14, i32 0)
store i64 %49, i64* %10
%50 = load i8*, i8** %14
%51 = load i8*, i8** %13
%52 = icmp eq i8* %50, %51
br i1 %52, label %53, label %54
53: ; preds = %47
br label %71
54: ; preds = %47
%55 = load i32, i32* %9
%56 = load i32, i32* %7
%57 = icmp sge i32 %55, %56
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %5
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %60)
store i32 -1, i32* %9
br label %73
62: ; preds = %54
%63 = load i64, i64* %10
%64 = load i64*, i64** %6
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
%67 = sext i32 %65 to i64
%68 = getelementptr inbounds i64, i64* %64, i64 %67
store i64 %63, i64* %68
br label %69
69: ; preds = %62
%70 = load i8*, i8** %14
store i8* %70, i8** %13
br label %47
71: ; preds = %53
br label %25
72: ; preds = %25
br label %73
73: ; preds = %72, %58
%74 = load i8*, i8** %12
%75 = call i32 @free(i8* %74)
%76 = load i32*, i32** %8
%77 = call i32 @fclose(i32* %76)
%78 = load i32, i32* %9
store i32 %78, i32* %4
br label %79
79: ; preds = %73, %18
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"No distribution data (%s: %s)\0A\00"
@errno = global i32 0
@.str.2 = [19 x i8] c"%s: too much data\0A\00"
define i32 @get_distribution(i8* %0, i64* nocapture writeonly %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = call i32 @getline(i8** %5, i64* %4, i32* %9)
%13 = icmp eq i32 %12, -1
br i1 %13, label %57, label %14
14: ; preds = %11
%15 = bitcast i8** %6 to i8*
br label %21
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = tail call i8* @strerror(i32 %18)
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %19)
br label %62
21: ; preds = %14, %53
%22 = phi i32 [ 0, %14 ], [ %54, %53 ]
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
switch i8 %24, label %25 [
i8 10, label %53
i8 35, label %53
]
25: ; preds = %21
%26 = call i64 @isalpha(i8 signext %24)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %53
28: ; preds = %25
%29 = load i8*, i8** %5
%30 = call i64 @strtol(i8* %29, i8** %6, i32 0)
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, %29
br i1 %32, label %53, label %33
33: ; preds = %28
%34 = sext i32 %22 to i64
%35 = call i32 @llvm.smax.i32(i32 %22, i32 %2)
%36 = sext i32 %35 to i64
br label %37
37: ; preds = %33, %45
%38 = phi i8* [ %31, %33 ], [ %49, %45 ]
%39 = phi i64 [ %34, %33 ], [ %46, %45 ]
%40 = phi i64 [ %30, %33 ], [ %48, %45 ]
%41 = icmp eq i64 %39, %36
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %57
45: ; preds = %37
%46 = add nsw i64 %39, 1
%47 = getelementptr inbounds i64, i64* %1, i64 %39
store i64 %40, i64* %47
%48 = call i64 @strtol(i8* %38, i8** %6, i32 0)
%49 = load i8*, i8** %6
%50 = icmp eq i8* %49, %38
br i1 %50, label %51, label %37
51: ; preds = %45
%52 = trunc i64 %46 to i32
br label %53
53: ; preds = %51, %28, %25, %21, %21
%54 = phi i32 [ %22, %21 ], [ %22, %21 ], [ %22, %25 ], [ %22, %28 ], [ %52, %51 ]
%55 = call i32 @getline(i8** %5, i64* %4, i32* %9)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %21
57: ; preds = %53, %11, %42
%58 = phi i32 [ -1, %42 ], [ 0, %11 ], [ %54, %53 ]
%59 = load i8*, i8** %5
%60 = call i32 @free(i8* %59)
%61 = call i32 @fclose(i32* %9)
br label %62
62: ; preds = %57, %16
%63 = phi i32 [ -1, %16 ], [ %58, %57 ]
ret i32 %63
}