#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 /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int *malloc(int);
int /*<<< orphan*/ printf(char *);
int get_node_stat(int *nodecount, int **num_in_links, int **num_out_links) {
  FILE *ip;
  int i;
  int src, dst;
  if ((ip = fopen("data_input", "r")) == NULL) {
    printf("Error opening the input file.\n");
    return 1;
  }
  fscanf(ip, "%d\n", nodecount);
  (*num_in_links) = malloc((*nodecount) * sizeof(int));
  (*num_out_links) = malloc((*nodecount) * sizeof(int));
  for (i = 0; i < (*nodecount); ++i) {
    (*num_in_links)[i] = 0;
    (*num_out_links)[i] = 0;
  }
  while (!feof(ip)) {
    fscanf(ip, "%d\t%d\n", &src, &dst);
    ++(*num_in_links)[dst];
    ++(*num_out_links)[src];
  }
  fclose(ip);
  return 0;
}


x86 assembly (clang, -O0):
<get_node_stat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xe85(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ad <get_node_stat+0x4d>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bd <get_node_stat+0x15d>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1243 <get_node_stat+0xe3>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x2c(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1202 <get_node_stat+0xa2>
jmp    1248 <get_node_stat+0xe8>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1266 <get_node_stat+0x106>
jmp    12ad <get_node_stat+0x14d>
mov    -0x28(%rbp),%rdi
lea    0xdbb(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
jmp    1248 <get_node_stat+0xe8>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_node_stat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe85(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1252 <get_node_stat+0xf2>
mov    %rax,%r12
lea    0xe76(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    (%rbx),%r13d
lea    0x0(,%r13,4),%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
test   %r13d,%r13d
jle    11ea <get_node_stat+0x8a>
mov    (%r15),%rcx
xor    %edx,%edx
movl   $0x0,(%rcx,%rdx,4)
movl   $0x0,(%rax,%rdx,4)
add    $0x1,%rdx
movslq (%rbx),%rsi
cmp    %rsi,%rdx
jl     11d0 <get_node_stat+0x70>
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1246 <get_node_stat+0xe6>
lea    0xe10(%rip),%r13
lea    0x4(%rsp),%rbx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    (%r15),%rax
movslq (%rsp),%rcx
addl   $0x1,(%rax,%rcx,4)
mov    (%r14),%rax
movslq 0x4(%rsp),%rcx
addl   $0x1,(%rax,%rcx,4)
mov    %r12,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     1210 <get_node_stat+0xb0>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1263 <get_node_stat+0x103>
lea    0xdbb(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"data_input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [7 x i8] c"%d\09%d\0A\00"
@str = [30 x i8] c"Error opening the input file.\00"
define i32 @get_node_stat(i32* %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*
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %3
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
br label %50
12: ; preds = %3
%13 = tail call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %0)
%14 = load i32, i32* %0
%15 = shl i32 %14, 2
%16 = tail call i32* @malloc(i32 %15)
store i32* %16, i32** %1
%17 = tail call i32* @malloc(i32 %15)
store i32* %17, i32** %2
%18 = icmp sgt i32 %14, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i32*, i32** %1
br label %24
21: ; preds = %24, %12
%22 = call i32 @feof(i32* %8)
%23 = icmp eq i32 %22, 0
br i1 %23, label %32, label %48
24: ; preds = %19, %24
%25 = phi i64 [ 0, %19 ], [ %28, %24 ]
%26 = getelementptr inbounds i32, i32* %20, i64 %25
store i32 0, i32* %26
%27 = getelementptr inbounds i32, i32* %17, i64 %25
store i32 0, i32* %27
%28 = add nuw nsw i64 %25, 1
%29 = load i32, i32* %0
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %24, label %21
32: ; preds = %21, %32
%33 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%34 = load i32*, i32** %1
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = add nsw i32 %38, 1
store i32 %39, i32* %37
%40 = load i32*, i32** %2
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
%45 = add nsw i32 %44, 1
store i32 %45, i32* %43
%46 = call i32 @feof(i32* %8)
%47 = icmp eq i32 %46, 0
br i1 %47, label %32, label %48
48: ; preds = %32, %21
%49 = call i32 @fclose(i32* %8)
br label %50
50: ; preds = %48, %10
%51 = phi i32 [ 1, %10 ], [ 0, %48 ]
ret i32 %51
}