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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ gmp_fscanf(int /*<<< orphan*/ *, char *, unsigned int *,
                      int /*<<< orphan*/);
int /*<<< orphan*/ mpz_clear(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned load_numbers(unsigned num_bits[], mpz_t nums[], const char file[],
                      size_t length) {
  unsigned p, i = 0;
  FILE *fp = fopen(file, "r");
  mpz_t tmp;
  if (NULL == fp)
    return 0;
  mpz_init(tmp);
  while (EOF != gmp_fscanf(fp, "%u\t%Zd\n", &p, tmp)) {
    mpz_init(nums[i]);
    mpz_set(nums[i], tmp);
    if (NULL != num_bits)
      num_bits[i] = p;
    i++;
    if (i >= length)
      break;
  }
  fclose(fp);
  mpz_clear(tmp);
  return i;
}


x86 assembly (clang, -O0):
<load_numbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
xor    %eax,%eax
cmp    -0x38(%rbp),%rax
jne    11ab <load_numbers+0x4b>
movl   $0x0,-0x4(%rbp)
jmp    1259 <load_numbers+0xf9>
mov    -0x3c(%rbp),%edi
call   1060 <mpz_init@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x3c(%rbp),%ecx
lea    0xe33(%rip),%rsi
lea    -0x2c(%rbp),%rdx
call   1050 <gmp_fscanf@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
je     1242 <load_numbers+0xe2>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
call   1060 <mpz_init@plt>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    (%rax,%rcx,4),%edi
mov    -0x3c(%rbp),%esi
call   1030 <mpz_set@plt>
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1222 <load_numbers+0xc2>
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%rax
jb     123d <load_numbers+0xdd>
jmp    1242 <load_numbers+0xe2>
jmp    11b3 <load_numbers+0x53>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x3c(%rbp),%edi
call   1070 <mpz_clear@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_numbers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe85(%rip),%rsi
mov    %rdx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fd <load_numbers+0x9d>
mov    %rax,%r13
call   1060 <mpz_init@plt>
xor    %ebx,%ebx
jmp    11a8 <load_numbers+0x48>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
cmp    %r14,%rbx
jae    11ee <load_numbers+0x8e>
mov    0x2e39(%rip),%rax
mov    (%rax),%rbp
mov    %r13,%rdi
lea    0xe46(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1050 <gmp_fscanf@plt>
cmp    %rax,%rbp
je     11ee <load_numbers+0x8e>
mov    %ebx,%ebp
mov    (%r15,%rbp,4),%edi
call   1060 <mpz_init@plt>
mov    (%r15,%rbp,4),%edi
call   1030 <mpz_set@plt>
test   %r12,%r12
je     11a0 <load_numbers+0x40>
mov    0x4(%rsp),%eax
mov    %eax,(%r12,%rbp,4)
jmp    11a0 <load_numbers+0x40>
mov    %r13,%rdi
call   1040 <fclose@plt>
call   1070 <mpz_clear@plt>
jmp    11ff <load_numbers+0x9f>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.1 = [8 x i8] c"%u\09%Zd\0A\00"
define i32 @load_numbers(i32* %0, i32* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i32 0, i32* %11
%14 = load i8*, i8** %8
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %12
%16 = load i32*, i32** %12
%17 = icmp eq i32* null, %16
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 0, i32* %5
br label %65
19: ; preds = %4
%20 = load i32, i32* %13
%21 = call i32 @mpz_init(i32 %20)
br label %22
22: ; preds = %58, %19
%23 = load i64, i64* @EOF
%24 = load i32*, i32** %12
%25 = load i32, i32* %13
%26 = call i64 @gmp_fscanf(i32* %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %10, i32 %25)
%27 = icmp ne i64 %23, %26
br i1 %27, label %28, label %59
28: ; preds = %22
%29 = load i32*, i32** %7
%30 = load i32, i32* %11
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @mpz_init(i32 %33)
%35 = load i32*, i32** %7
%36 = load i32, i32* %11
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = load i32, i32* %38
%40 = load i32, i32* %13
%41 = call i32 @mpz_set(i32 %39, i32 %40)
%42 = load i32*, i32** %6
%43 = icmp ne i32* null, %42
br i1 %43, label %44, label %50
44: ; preds = %28
%45 = load i32, i32* %10
%46 = load i32*, i32** %6
%47 = load i32, i32* %11
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %44, %28
%51 = load i32, i32* %11
%52 = add i32 %51, 1
store i32 %52, i32* %11
%53 = load i32, i32* %11
%54 = zext i32 %53 to i64
%55 = load i64, i64* %9
%56 = icmp uge i64 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %50
br label %59
58: ; preds = %50
br label %22
59: ; preds = %57, %22
%60 = load i32*, i32** %12
%61 = call i32 @fclose(i32* %60)
%62 = load i32, i32* %13
%63 = call i32 @mpz_clear(i32 %62)
%64 = load i32, i32* %11
store i32 %64, i32* %5
br label %65
65: ; preds = %59, %18
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i64 0
@.str.1 = [8 x i8] c"%u\09%Zd\0A\00"
define i32 @load_numbers(i32* writeonly %0, i32* nocapture %1, i8* nocapture %2, i64 %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %4
%10 = tail call i32 @mpz_init(i32 undef)
%11 = icmp eq i32* %0, null
br label %12
12: ; preds = %27, %9
%13 = phi i32 [ 0, %9 ], [ %28, %27 ]
%14 = load i64, i64* @EOF
%15 = call i64 @gmp_fscanf(i32* %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32 undef)
%16 = icmp eq i64 %14, %15
br i1 %16, label %31, label %17
17: ; preds = %12
%18 = zext i32 %13 to i64
%19 = getelementptr inbounds i32, i32* %1, i64 %18
%20 = load i32, i32* %19
%21 = call i32 @mpz_init(i32 %20)
%22 = load i32, i32* %19
%23 = call i32 @mpz_set(i32 %22, i32 undef)
br i1 %11, label %27, label %24
24: ; preds = %17
%25 = load i32, i32* %5
%26 = getelementptr inbounds i32, i32* %0, i64 %18
store i32 %25, i32* %26
br label %27
27: ; preds = %24, %17
%28 = add i32 %13, 1
%29 = zext i32 %28 to i64
%30 = icmp ult i64 %29, %3
br i1 %30, label %12, label %31
31: ; preds = %27, %12
%32 = phi i32 [ %28, %27 ], [ %13, %12 ]
%33 = call i32 @fclose(i32* %7)
%34 = call i32 @mpz_clear(i32 undef)
br label %35
35: ; preds = %4, %31
%36 = phi i32 [ %32, %31 ], [ 0, %4 ]
ret i32 %36
}