#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 */

/* Variables and functions */
scalar_t__ malloc(int);
scalar_t__ realloc(int **, int);
int sscanf(char *, char *, int *, int *);
void addRow(int **numrows, int *numcols, int ****head, char *line) {
  ++(**numrows);
  **head = (int **)realloc(**head, sizeof(int *) * (**numrows));
  int *newRow;
  newRow = (int *)malloc(sizeof(int) * (*numcols));
  int n, val, j = 0;
  while (1 <= sscanf(line, "%d%n", &val, &n)) {
    line += n;
    newRow[j] = val;
    j++;
  }
  (**head)[**numrows - 1] = newRow;
}


x86 assembly (clang, -O0):
<addRow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq (%rax),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe56(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
jg     11f3 <addRow+0xc3>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%edx
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    119f <addRow+0x6f>
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addRow>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %rdi,0x10(%rsp)
mov    (%rdi),%rax
mov    (%rax),%ecx
lea    0x1(%rcx),%edx
mov    %edx,(%rax)
mov    (%r15),%rax
mov    (%rax),%rdi
lea    0x8(,%rcx,8),%esi
call   1050 <realloc@plt>
mov    (%r15),%rcx
mov    %rax,(%rcx)
mov    0x0(%rbp),%edi
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0xe7b(%rip),%rsi
mov    %rsp,%rdx
lea    0x4(%rsp),%rcx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
test   %eax,%eax
jle    11d8 <addRow+0xa8>
lea    0xe60(%rip),%r13
mov    %rsp,%rbp
lea    0x4(%rsp),%r14
mov    0x8(%rsp),%r12
nopl   (%rax)
movslq 0x4(%rsp),%rax
add    %rax,%rbx
mov    (%rsp),%eax
mov    %eax,(%r12)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1040 <sscanf@plt>
add    $0x4,%r12
test   %eax,%eax
jg     11b0 <addRow+0x80>
mov    (%r15),%rax
mov    (%rax),%rax
mov    0x10(%rsp),%rcx
mov    (%rcx),%rcx
movslq (%rcx),%rcx
mov    0x8(%rsp),%rdx
mov    %rdx,-0x8(%rax,%rcx,8)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%n\00"
define void @addRow(i32** %0, i32* %1, i32**** %2, i8* %3) {
%5 = alloca i32**
%6 = alloca i32*
%7 = alloca i32****
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32** %0, i32*** %5
store i32* %1, i32** %6
store i32**** %2, i32***** %7
store i8* %3, i8** %8
%13 = load i32**, i32*** %5
%14 = load i32*, i32** %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
%17 = load i32****, i32***** %7
%18 = load i32***, i32**** %17
%19 = load i32**, i32*** %18
%20 = load i32**, i32*** %5
%21 = load i32*, i32** %20
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = mul i64 8, %23
%25 = trunc i64 %24 to i32
%26 = call i64 @realloc(i32** %19, i32 %25)
%27 = inttoptr i64 %26 to i32**
%28 = load i32****, i32***** %7
%29 = load i32***, i32**** %28
store i32** %27, i32*** %29
%30 = load i32*, i32** %6
%31 = load i32, i32* %30
%32 = sext i32 %31 to i64
%33 = mul i64 4, %32
%34 = trunc i64 %33 to i32
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to i32*
store i32* %36, i32** %9
store i32 0, i32* %12
br label %37
37: ; preds = %41, %4
%38 = load i8*, i8** %8
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %11, i32* %10)
%40 = icmp sle i32 1, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i32, i32* %10
%43 = load i8*, i8** %8
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8* %45, i8** %8
%46 = load i32, i32* %11
%47 = load i32*, i32** %9
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 %46, i32* %50
%51 = load i32, i32* %12
%52 = add nsw i32 %51, 1
store i32 %52, i32* %12
br label %37
53: ; preds = %37
%54 = load i32*, i32** %9
%55 = load i32****, i32***** %7
%56 = load i32***, i32**** %55
%57 = load i32**, i32*** %56
%58 = load i32**, i32*** %5
%59 = load i32*, i32** %58
%60 = load i32, i32* %59
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32*, i32** %57, i64 %62
store i32* %54, i32** %63
ret void
}

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