#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);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read_matrix(char *, char *, int);
int /*<<< orphan*/ text2numeric_matrix(int *, char *, int, int);
int main() {
  int length = 20 * (20 * 2 + 20), i;
  char *data = (char *)malloc(length);
  char *name = {"in.txt"};
  int *matrix = (int *)malloc((20 * 20) * sizeof(int));
  for (i = 0; i < 20 * 20; i++)
    matrix[i] = 0;
  read_matrix(data, &name[0], length);
  text2numeric_matrix(matrix, data, length, 2);
  printf("exiting\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4b0,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    $0x640,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x190,-0xc(%rbp)
jge    11ac <main+0x6c>
mov    -0x28(%rbp),%rax
movslq -0xc(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <main+0x42>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1060 <read_matrix@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    $0x2,%ecx
call   1030 <text2numeric_matrix@plt>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x4b0,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    $0x640,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x640,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
mov    $0x4b0,%edx
call   1070 <read_matrix@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4b0,%edx
mov    $0x2,%ecx
call   1030 <text2numeric_matrix@plt>
lea    0xe5a(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"in.txt\00"
@.str.1 = [9 x i8] c"exiting\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i32 0, i32* %1
store i32 1200, i32* %2
%7 = load i32, i32* %2
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %5
%10 = call i64 @malloc(i32 1600)
%11 = inttoptr i64 %10 to i32*
store i32* %11, i32** %6
store i32 0, i32* %3
br label %12
12: ; preds = %20, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 400
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32*, i32** %6
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
store i32 0, i32* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %12
23: ; preds = %12
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i32, i32* %2
%28 = call i32 @read_matrix(i8* %24, i8* %26, i32 %27)
%29 = load i32*, i32** %6
%30 = load i8*, i8** %4
%31 = load i32, i32* %2
%32 = call i32 @text2numeric_matrix(i32* %29, i8* %30, i32 %31, i32 2)
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"in.txt\00"
@str = [8 x i8] c"exiting\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 1200)
%2 = tail call i64 @malloc(i32 1600)
%3 = inttoptr i64 %2 to i32*
%4 = inttoptr i64 %2 to i8*
%5 = inttoptr i64 %1 to i8*
%6 = tail call i32 @read_matrix(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1200)
%7 = tail call i32 @text2numeric_matrix(i32* %3, i8* %5, i32 1200, i32 2)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}