#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 */
unsigned int atoi(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
unsigned int *malloc(unsigned int);
unsigned int *realloc(unsigned int *, unsigned int);
char *strtok(char *, char *);
int read_ij(FILE *filein, unsigned int **I, unsigned int **J) {
  unsigned int size, K;
  char buff[256];
  char *ptr;
  size = 20;
  K = 0;
  *I = malloc(size * sizeof(unsigned int));
  *J = malloc(size * sizeof(unsigned int));
  while (fgets(buff, 256, filein)) {
    if (buff[0] == '#')
      continue;
    if (K == size) {
      size += 20;
      *I = realloc(*I, size * sizeof(unsigned int));
      *J = realloc(*J, size * sizeof(unsigned int));
    }
    ptr = strtok(buff, " ");
    (*I)[K] = atoi(ptr);
    ptr = strtok(NULL, " ");
    (*J)[K] = atoi(ptr);
    K += 1;
  }
  *I = realloc(*I, K * sizeof(unsigned int));
  *J = realloc(*J, K * sizeof(unsigned int));
  return K;
}


x86 assembly (clang, -O0):
<read_ij>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x14,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     12a1 <read_ij+0x151>
movsbl -0x120(%rbp),%eax
cmp    $0x23,%eax
jne    11d9 <read_ij+0x89>
jmp    11a5 <read_ij+0x55>
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    122c <read_ij+0xdc>
mov    -0x1c(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x120(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd94(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a5 <read_ij+0x55>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ij>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x50,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
mov    $0x50,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14)
mov    $0x14,%ebp
xor    %r12d,%r12d
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     123d <read_ij+0xed>
cmpb   $0x23,0x10(%rsp)
je     11a0 <read_ij+0x50>
mov    %ebp,0xc(%rsp)
cmp    %ebp,%r12d
jne    11f4 <read_ij+0xa4>
lea    0x14(%r12),%eax
mov    %eax,0xc(%rsp)
mov    (%r15),%rdi
lea    0x50(,%r12,4),%ebp
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
mov    (%r14),%rdi
mov    %ebp,%esi
call   1050 <realloc@plt>
mov    %rax,(%r14)
mov    %r13,%rdi
lea    0xe02(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%r15),%rcx
mov    %r12d,%ebp
mov    %eax,(%rcx,%rbp,4)
xor    %edi,%edi
lea    0xde3(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%r14),%rcx
mov    %eax,(%rcx,%rbp,4)
add    $0x1,%r12d
mov    0xc(%rsp),%ebp
jmp    11a0 <read_ij+0x50>
mov    (%r15),%rdi
lea    0x0(,%r12,4),%ebx
mov    %ebx,%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
mov    (%r14),%rdi
mov    %ebx,%esi
call   1050 <realloc@plt>
mov    %rax,(%r14)
mov    %r12d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @read_ij(i32* %0, i32** %1, i32** %2) {
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8]
%10 = alloca i8*
store i32* %0, i32** %4
store i32** %1, i32*** %5
store i32** %2, i32*** %6
store i32 20, i32* %7
store i32 0, i32* %8
%11 = load i32, i32* %7
%12 = zext i32 %11 to i64
%13 = mul i64 %12, 4
%14 = trunc i64 %13 to i32
%15 = call i32* @malloc(i32 %14)
%16 = load i32**, i32*** %5
store i32* %15, i32** %16
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = trunc i64 %19 to i32
%21 = call i32* @malloc(i32 %20)
%22 = load i32**, i32*** %6
store i32* %21, i32** %22
br label %23
23: ; preds = %57, %33, %3
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = load i32*, i32** %4
%26 = call i64 @fgets(i8* %24, i32 256, i32* %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %77
28: ; preds = %23
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 35
br i1 %32, label %33, label %34
33: ; preds = %28
br label %23
34: ; preds = %28
%35 = load i32, i32* %8
%36 = load i32, i32* %7
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %57
38: ; preds = %34
%39 = load i32, i32* %7
%40 = add i32 %39, 20
store i32 %40, i32* %7
%41 = load i32**, i32*** %5
%42 = load i32*, i32** %41
%43 = load i32, i32* %7
%44 = zext i32 %43 to i64
%45 = mul i64 %44, 4
%46 = trunc i64 %45 to i32
%47 = call i32* @realloc(i32* %42, i32 %46)
%48 = load i32**, i32*** %5
store i32* %47, i32** %48
%49 = load i32**, i32*** %6
%50 = load i32*, i32** %49
%51 = load i32, i32* %7
%52 = zext i32 %51 to i64
%53 = mul i64 %52, 4
%54 = trunc i64 %53 to i32
%55 = call i32* @realloc(i32* %50, i32 %54)
%56 = load i32**, i32*** %6
store i32* %55, i32** %56
br label %57
57: ; preds = %38, %34
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%59 = call i8* @strtok(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %59, i8** %10
%60 = load i8*, i8** %10
%61 = call i32 @atoi(i8* %60)
%62 = load i32**, i32*** %5
%63 = load i32*, i32** %62
%64 = load i32, i32* %8
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
store i32 %61, i32* %66
%67 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %67, i8** %10
%68 = load i8*, i8** %10
%69 = call i32 @atoi(i8* %68)
%70 = load i32**, i32*** %6
%71 = load i32*, i32** %70
%72 = load i32, i32* %8
%73 = zext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %71, i64 %73
store i32 %69, i32* %74
%75 = load i32, i32* %8
%76 = add i32 %75, 1
store i32 %76, i32* %8
br label %23
77: ; preds = %23
%78 = load i32**, i32*** %5
%79 = load i32*, i32** %78
%80 = load i32, i32* %8
%81 = zext i32 %80 to i64
%82 = mul i64 %81, 4
%83 = trunc i64 %82 to i32
%84 = call i32* @realloc(i32* %79, i32 %83)
%85 = load i32**, i32*** %5
store i32* %84, i32** %85
%86 = load i32**, i32*** %6
%87 = load i32*, i32** %86
%88 = load i32, i32* %8
%89 = zext i32 %88 to i64
%90 = mul i64 %89, 4
%91 = trunc i64 %90 to i32
%92 = call i32* @realloc(i32* %87, i32 %91)
%93 = load i32**, i32*** %6
store i32* %92, i32** %93
%94 = load i32, i32* %8
ret i32 %94
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @read_ij(i32* nocapture %0, i32** nocapture %1, i32** nocapture %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32* @malloc(i32 80)
store i32* %6, i32** %1
%7 = tail call i32* @malloc(i32 80)
store i32* %7, i32** %2
br label %8
8: ; preds = %26, %3
%9 = phi i32 [ %37, %26 ], [ 0, %3 ]
%10 = phi i32 [ %27, %26 ], [ 20, %3 ]
br label %11
11: ; preds = %8, %14
%12 = call i64 @fgets(i8* %5, i32 256, i32* %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %38, label %14
14: ; preds = %11
%15 = load i8, i8* %5
%16 = icmp eq i8 %15, 35
br i1 %16, label %11, label %17
17: ; preds = %14
%18 = icmp eq i32 %9, %10
br i1 %18, label %19, label %26
19: ; preds = %17
%20 = add i32 %9, 20
%21 = load i32*, i32** %1
%22 = shl i32 %20, 2
%23 = call i32* @realloc(i32* %21, i32 %22)
store i32* %23, i32** %1
%24 = load i32*, i32** %2
%25 = call i32* @realloc(i32* %24, i32 %22)
store i32* %25, i32** %2
br label %26
26: ; preds = %19, %17
%27 = phi i32 [ %20, %19 ], [ %10, %17 ]
%28 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @atoi(i8* %28)
%30 = load i32*, i32** %1
%31 = zext i32 %9 to i64
%32 = getelementptr inbounds i32, i32* %30, i64 %31
store i32 %29, i32* %32
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @atoi(i8* %33)
%35 = load i32*, i32** %2
%36 = getelementptr inbounds i32, i32* %35, i64 %31
store i32 %34, i32* %36
%37 = add i32 %9, 1
br label %8
38: ; preds = %11
%39 = load i32*, i32** %1
%40 = shl i32 %9, 2
%41 = call i32* @realloc(i32* %39, i32 %40)
store i32* %41, i32** %1
%42 = load i32*, i32** %2
%43 = call i32* @realloc(i32* %42, i32 %40)
store i32* %43, i32** %2
ret i32 %9
}