#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ init_pairing_natural(int *, int);
int *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
char *strtok(char *, char *);
void load_pairing(int **pairing, int N, char *fname) {
  FILE *f;
  int i, j, num;
  char buff[256];
  char *ptr;
  f = fopen(fname, "r");
  if (!f) {
    printf("Error opening file \"%s\"!!!! Exiting....\n", fname);
    exit(2);
  }
  if (*pairing == NULL) {
    *pairing = malloc(N * sizeof(int));
    init_pairing_natural(*pairing, N);
  }
  num = 0;
  while (num < N) {
    fgets(buff, 255, f);
    if (buff[0] == '#')
      continue;
    ptr = strtok(buff, " ");
    i = atoi(ptr);
    ptr = strtok(NULL, " ");
    j = atoi(ptr);
    (*pairing)[i] = j;
    num += 1;
  }
}


x86 assembly (clang, -O0):
<load_pairing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <load_pairing+0x4f>
mov    -0x18(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1205 <load_pairing+0x85>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0xc(%rbp),%esi
call   1040 <init_pairing_natural@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12b0 <load_pairing+0x130>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
movsbl -0x130(%rbp),%eax
cmp    $0x23,%eax
jne    1242 <load_pairing+0xc2>
jmp    120c <load_pairing+0x8c>
lea    -0x130(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb5(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120c <load_pairing+0x8c>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_pairing>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r12
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
lea    0xe5d(%rip),%rsi
mov    %rdx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1264 <load_pairing+0xe4>
mov    %rax,%rbx
cmpq   $0x0,(%r15)
jne    11dd <load_pairing+0x5d>
mov    0x8(%rsp),%r14
lea    0x0(,%r14,4),%edi
call   1060 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %r14d,%esi
call   1040 <init_pairing_natural@plt>
cmpl   $0x0,0x8(%rsp)
jle    1252 <load_pairing+0xd2>
xor    %r14d,%r14d
lea    0x10(%rsp),%r12
lea    0xe38(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
cmpb   $0x23,0x10(%rsp)
je     1200 <load_pairing+0x80>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
call   1090 <atoi@plt>
mov    (%r15),%rcx
movslq %ebp,%rdx
mov    %eax,(%rcx,%rdx,4)
add    $0x1,%r14d
cmp    0x8(%rsp),%r14d
jne    1200 <load_pairing+0x80>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd97(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [41 x i8] c"Error opening file \22%s\22!!!! Exiting....\0A\00"
@.str.2 = [2 x i8] c" \00"
define void @load_pairing(i32** %0, i32 %1, i8* %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [256 x i8]
%12 = alloca i8*
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%13 = load i8*, i8** %6
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %3
%22 = load i32**, i32*** %4
%23 = load i32*, i32** %22
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 4
%29 = trunc i64 %28 to i32
%30 = call i32* @malloc(i32 %29)
%31 = load i32**, i32*** %4
store i32* %30, i32** %31
%32 = load i32**, i32*** %4
%33 = load i32*, i32** %32
%34 = load i32, i32* %5
%35 = call i32 @init_pairing_natural(i32* %33, i32 %34)
br label %36
36: ; preds = %25, %21
store i32 0, i32* %10
br label %37
37: ; preds = %50, %49, %36
%38 = load i32, i32* %10
%39 = load i32, i32* %5
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %66
41: ; preds = %37
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%43 = load i32*, i32** %7
%44 = call i32 @fgets(i8* %42, i32 255, i32* %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 35
br i1 %48, label %49, label %50
49: ; preds = %41
br label %37
50: ; preds = %41
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%52 = call i8* @strtok(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %52, i8** %12
%53 = load i8*, i8** %12
%54 = call i32 @atoi(i8* %53)
store i32 %54, i32* %8
%55 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %55, i8** %12
%56 = load i8*, i8** %12
%57 = call i32 @atoi(i8* %56)
store i32 %57, i32* %9
%58 = load i32, i32* %9
%59 = load i32**, i32*** %4
%60 = load i32*, i32** %59
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
store i32 %58, i32* %63
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %37
66: ; preds = %37
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [41 x i8] c"Error opening file \22%s\22!!!! Exiting....\0A\00"
@.str.2 = [2 x i8] c" \00"
define void @load_pairing(i32** nocapture %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %3
%12 = load i32*, i32** %0
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = shl i32 %1, 2
%16 = tail call i32* @malloc(i32 %15)
store i32* %16, i32** %0
%17 = tail call i32 @init_pairing_natural(i32* %16, i32 %1)
br label %18
18: ; preds = %14, %11
%19 = icmp sgt i32 %1, 0
br i1 %19, label %20, label %36
20: ; preds = %18, %26
%21 = phi i32 [ %34, %26 ], [ 0, %18 ]
br label %22
22: ; preds = %20, %22
%23 = call i32 @fgets(i8* %5, i32 255, i32* %6)
%24 = load i8, i8* %5
%25 = icmp eq i8 %24, 35
br i1 %25, label %22, label %26
26: ; preds = %22
%27 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @atoi(i8* %27)
%29 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @atoi(i8* %29)
%31 = load i32*, i32** %0
%32 = sext i32 %28 to i64
%33 = getelementptr inbounds i32, i32* %31, i64 %32
store i32 %30, i32* %33
%34 = add nuw nsw i32 %21, 1
%35 = icmp eq i32 %34, %1
br i1 %35, label %36, label %20
36: ; preds = %26, %18
ret void
}