#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(int);
unsigned int *realloc(unsigned int *, int);
char *strtok(char *, char *);
int read_stubs(FILE *filein, unsigned int **S) {
  int size, K;
  char buff[256];
  char *ptr;
  K = 0;
  size = 20;
  *S = malloc(size * sizeof(unsigned int));
  while (fgets(buff, 256, filein)) {
    if (K == size) {
      size += 20;
      *S = realloc(*S, size * sizeof(unsigned int));
    }
    ptr = strtok(buff, " ");
    (*S)[K++] = atoi(ptr);
    ptr = strtok(NULL, " ");
    (*S)[K++] = atoi(ptr);
  }
  *S = realloc(*S, K * sizeof(unsigned int));
  return K;
}


x86 assembly (clang, -O0):
<read_stubs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x14,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x100,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1260 <read_stubs+0x110>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11de <read_stubs+0x8e>
mov    -0x14(%rbp),%eax
add    $0x14,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x120(%rbp),%rdi
lea    0xe14(%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    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd7(%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    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    118a <read_stubs+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stubs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x50,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     1238 <read_stubs+0xe8>
mov    $0x14,%r13d
xor    %ebx,%ebx
lea    0xe64(%rip),%rbp
mov    %rsp,%r12
jmp    11fb <read_stubs+0xab>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%r15),%rcx
mov    %eax,(%rcx,%rbx,4)
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    (%r15),%rcx
mov    %eax,0x4(%rcx,%rbx,4)
add    $0x2,%rbx
mov    %r12,%rdi
mov    $0x100,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     123a <read_stubs+0xea>
mov    %r13d,%eax
cmp    %rax,%rbx
jne    11b0 <read_stubs+0x60>
mov    (%r15),%rdi
mov    %r12,%rbp
mov    %r14,%r12
mov    %r13d,%r14d
add    $0x14,%r14d
lea    0x50(,%r13,4),%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
mov    %r14d,%r13d
mov    %r12,%r14
mov    %rbp,%r12
lea    0xdcd(%rip),%rbp
jmp    11b0 <read_stubs+0x60>
xor    %ebx,%ebx
mov    (%r15),%rdi
lea    0x0(,%rbx,4),%esi
call   1050 <realloc@plt>
mov    %rax,(%r15)
mov    %ebx,%eax
add    $0x108,%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_stubs(i32* %0, i32** %1) {
%3 = alloca i32*
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i8*
store i32* %0, i32** %3
store i32** %1, i32*** %4
store i32 0, i32* %6
store i32 20, i32* %5
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
%14 = load i32**, i32*** %4
store i32* %13, i32** %14
br label %15
15: ; preds = %35, %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fgets(i8* %16, i32 256, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %55
20: ; preds = %15
%21 = load i32, i32* %6
%22 = load i32, i32* %5
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 20
store i32 %26, i32* %5
%27 = load i32**, i32*** %4
%28 = load i32*, i32** %27
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 4
%32 = trunc i64 %31 to i32
%33 = call i32* @realloc(i32* %28, i32 %32)
%34 = load i32**, i32*** %4
store i32* %33, i32** %34
br label %35
35: ; preds = %24, %20
%36 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%37 = call i8* @strtok(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = call i32 @atoi(i8* %38)
%40 = load i32**, i32*** %4
%41 = load i32*, i32** %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i32, i32* %41, i64 %44
store i32 %39, i32* %45
%46 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %46, i8** %8
%47 = load i8*, i8** %8
%48 = call i32 @atoi(i8* %47)
%49 = load i32**, i32*** %4
%50 = load i32*, i32** %49
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i32, i32* %50, i64 %53
store i32 %48, i32* %54
br label %15
55: ; preds = %15
%56 = load i32**, i32*** %4
%57 = load i32*, i32** %56
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = mul i64 %59, 4
%61 = trunc i64 %60 to i32
%62 = call i32* @realloc(i32* %57, i32 %61)
%63 = load i32**, i32*** %4
store i32* %62, i32** %63
%64 = load i32, i32* %6
ret i32 %64
}

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