#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ freeTriangle(char **, int);
int /*<<< orphan*/ printf(char *, int);
char **readTriangle(int /*<<< orphan*/ *, int *);
int solveTriangle(char **, int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  FILE *file = fopen("triangle.txt", "r");
  if (file == NULL) {
    return EXIT_FAILURE;
  }
  int rows;
  char **triangle = readTriangle(file, &rows);
  fclose(file);
  if (triangle == NULL) {
    return EXIT_FAILURE;
  }
  if (rows > 0) {
    printf("Solution: %d.\n", solveTriangle(triangle, 0, 0, rows));
  }
  freeTriangle(triangle, rows);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <main+0x49>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121f <main+0xbf>
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <readTriangle@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11df <main+0x7f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    121f <main+0xbf>
cmpl   $0x0,-0x1c(%rbp)
jle    1207 <main+0xa7>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
xor    %edx,%edx
mov    %edx,%esi
call   1060 <solveTriangle@plt>
mov    %eax,%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <freeTriangle@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d5 <main+0x75>
mov    %rax,%rbx
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1070 <readTriangle@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %r14,%r14
je     11d5 <main+0x75>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    11c2 <main+0x62>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <solveTriangle@plt>
lea    0xe58(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0x4(%rsp),%ecx
mov    %r14,%rdi
mov    %ecx,%esi
call   1050 <freeTriangle@plt>
mov    0x2e05(%rip),%rax
jmp    11dc <main+0x7c>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"triangle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [15 x i8] c"Solution: %d.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %36
14: ; preds = %2
%15 = load i32*, i32** %6
%16 = call i8** @readTriangle(i32* %15, i32* %7)
store i8** %16, i8*** %8
%17 = load i32*, i32** %6
%18 = call i32 @fclose(i32* %17)
%19 = load i8**, i8*** %8
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %23
21: ; preds = %14
%22 = load i32, i32* @EXIT_FAILURE
store i32 %22, i32* %3
br label %36
23: ; preds = %14
%24 = load i32, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8**, i8*** %8
%28 = load i32, i32* %7
%29 = call i32 @solveTriangle(i8** %27, i32 0, i32 0, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26, %23
%32 = load i8**, i8*** %8
%33 = load i32, i32* %7
%34 = call i32 @freeTriangle(i8** %32, i32 %33)
%35 = load i32, i32* @EXIT_SUCCESS
store i32 %35, i32* %3
br label %36
36: ; preds = %31, %21, %12
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [13 x i8] c"triangle.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [15 x i8] c"Solution: %d.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = load i32, i32* @EXIT_FAILURE
br label %26
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
%10 = call i8** @readTriangle(i32* %4, i32* %3)
%11 = call i32 @fclose(i32* %4)
%12 = icmp eq i8** %10, null
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i32 @solveTriangle(i8** %10, i32 0, i32 0, i32 %14)
%18 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = load i32, i32* %3
br label %20
20: ; preds = %16, %13
%21 = phi i32 [ %19, %16 ], [ %14, %13 ]
%22 = call i32 @freeTriangle(i8** %10, i32 %21)
br label %23
23: ; preds = %8, %20
%24 = phi i32* [ @EXIT_SUCCESS, %20 ], [ @EXIT_FAILURE, %8 ]
%25 = load i32, i32* %24
br label %26
26: ; preds = %23, %6
%27 = phi i32 [ %7, %6 ], [ %25, %23 ]
ret i32 %27
}