#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int *malloc(int);
int *load_discrete1(char *fname, int *dim, int *max) {
  FILE *f;
  int *x;
  int i, j, k;
  *dim = 0;
  *max = 0;
  k = 0;
  f = fopen(fname, "r");
  while (!feof(f)) {
    i = fscanf(f, "%d", &j);
    if (i > 0) {
      k++;
      if (j > *max) {
        *max = j;
      }
    }
  }
  *dim = k;
  fclose(f);
  x = malloc(*dim * sizeof(int));
  f = fopen(fname, "r");
  j = 0;
  while (!feof(f)) {
    i = fscanf(f, "%d", &k);
    if (i > 0) {
      x[j] = k;
      j++;
    }
  }
  fclose(f);
  return x;
}


x86 assembly (clang, -O0):
<load_discrete1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <load_discrete1+0x61>
jmp    11fd <load_discrete1+0xad>
mov    -0x20(%rbp),%rdi
lea    0xe46(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    11f8 <load_discrete1+0xa8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    11f3 <load_discrete1+0xa3>
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11f8 <load_discrete1+0xa8>
jmp    1193 <load_discrete1+0x43>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdd0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    125e <load_discrete1+0x10e>
jmp    129b <load_discrete1+0x14b>
mov    -0x20(%rbp),%rdi
lea    0xd99(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    1296 <load_discrete1+0x146>
mov    -0x34(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1240 <load_discrete1+0xf0>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_discrete1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
movl   $0x0,(%rsi)
movl   $0x0,(%rdx)
movl   $0x0,0xc(%rsp)
lea    0xe81(%rip),%rsi
mov    %rdi,0x10(%rsp)
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     11f6 <load_discrete1+0xa6>
mov    %r14d,(%r15)
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%r15),%edi
shl    $0x2,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe45(%rip),%rsi
mov    0x10(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
movl   $0x0,0x8(%rsp)
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     124b <load_discrete1+0xfb>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
lea    0xe02(%rip),%r13
lea    0x8(%rsp),%rbp
jmp    1220 <load_discrete1+0xd0>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    119b <load_discrete1+0x4b>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
test   %eax,%eax
jle    1210 <load_discrete1+0xc0>
add    $0x1,%r14d
mov    %r14d,0xc(%rsp)
mov    0x8(%rsp),%eax
cmp    (%r12),%eax
jle    1210 <load_discrete1+0xc0>
mov    %eax,(%r12)
jmp    1210 <load_discrete1+0xc0>
lea    0xdb0(%rip),%r14
lea    0xc(%rsp),%rbp
jmp    1270 <load_discrete1+0x120>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11dc <load_discrete1+0x8c>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
test   %eax,%eax
jle    1260 <load_discrete1+0x110>
mov    0xc(%rsp),%eax
movslq 0x8(%rsp),%rcx
mov    %eax,(%r15,%rcx,4)
lea    0x1(%rcx),%eax
mov    %eax,0x8(%rsp)
jmp    1260 <load_discrete1+0x110>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define i32* @load_discrete1(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%12 = load i32*, i32** %5
store i32 0, i32* %12
%13 = load i32*, i32** %6
store i32 0, i32* %13
store i32 0, i32* %11
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
br label %16
16: ; preds = %37, %3
%17 = load i32*, i32** %7
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %38
21: ; preds = %16
%22 = load i32*, i32** %7
%23 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %21
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 1
store i32 %28, i32* %11
%29 = load i32, i32* %10
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = icmp sgt i32 %29, %31
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %10
%35 = load i32*, i32** %6
store i32 %34, i32* %35
br label %36
36: ; preds = %33, %26
br label %37
37: ; preds = %36, %21
br label %16
38: ; preds = %16
%39 = load i32, i32* %11
%40 = load i32*, i32** %5
store i32 %39, i32* %40
%41 = load i32*, i32** %7
%42 = call i32 @fclose(i32* %41)
%43 = load i32*, i32** %5
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 4
%47 = trunc i64 %46 to i32
%48 = call i32* @malloc(i32 %47)
store i32* %48, i32** %8
%49 = load i8*, i8** %4
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %50, i32** %7
store i32 0, i32* %10
br label %51
51: ; preds = %69, %38
%52 = load i32*, i32** %7
%53 = call i32 @feof(i32* %52)
%54 = icmp ne i32 %53, 0
%55 = xor i1 %54, true
br i1 %55, label %56, label %70
56: ; preds = %51
%57 = load i32*, i32** %7
%58 = call i32 @fscanf(i32* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %11)
store i32 %58, i32* %9
%59 = load i32, i32* %9
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %69
61: ; preds = %56
%62 = load i32, i32* %11
%63 = load i32*, i32** %8
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
store i32 %62, i32* %66
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %69
69: ; preds = %61, %56
br label %51
70: ; preds = %51
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
%73 = load i32*, i32** %8
ret i32* %73
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
define noalias i32* @load_discrete1(i8* nocapture %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %5
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @feof(i32* %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %3, %21
%12 = phi i32 [ %22, %21 ], [ 0, %3 ]
%13 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = add nsw i32 %12, 1
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = load i32, i32* %2
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 %17, i32* %2
br label %21
21: ; preds = %15, %20, %11
%22 = phi i32 [ %16, %15 ], [ %16, %20 ], [ %12, %11 ]
%23 = call i32 @feof(i32* %8)
%24 = icmp eq i32 %23, 0
br i1 %24, label %11, label %25
25: ; preds = %21, %3
%26 = phi i32 [ 0, %3 ], [ %22, %21 ]
store i32 %26, i32* %1
%27 = call i32 @fclose(i32* %8)
%28 = load i32, i32* %1
%29 = shl i32 %28, 2
%30 = call i32* @malloc(i32 %29)
%31 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
%32 = call i32 @feof(i32* %31)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %46
34: ; preds = %25, %43
%35 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %34
%38 = load i32, i32* %5
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %30, i64 %40
store i32 %38, i32* %41
%42 = add nsw i32 %39, 1
store i32 %42, i32* %4
br label %43
43: ; preds = %37, %34
%44 = call i32 @feof(i32* %31)
%45 = icmp eq i32 %44, 0
br i1 %45, label %34, label %46
46: ; preds = %43, %25
%47 = call i32 @fclose(i32* %31)
ret i32* %30
}