#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 minPathSum(int **, int, int);
int /*<<< orphan*/ printf(char *, int);
int main(void) {
  int **grid = (int **)malloc(sizeof(int *) * 2);
  for (int i = 0; i < 2; i++)
    grid[i] = (int *)malloc(sizeof(int) * 2);
  grid[0][0] = 1;
  grid[0][1] = 2;
  grid[1][0] = 1;
  grid[1][1] = 1;
  printf("%d\n", minPathSum(grid, 2, 2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    1185 <main+0x55>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <main+0x24>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movl   $0x1,0x4(%rax)
mov    -0x10(%rbp),%rdi
mov    $0x2,%edx
mov    %edx,%esi
call   1050 <minPathSum@plt>
mov    %eax,%esi
lea    0xe2a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    (%rbx),%rcx
movabs $0x200000001,%rdx
mov    %rdx,(%rcx)
movabs $0x100000001,%rcx
mov    %rcx,(%rax)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x2,%edx
call   1050 <minPathSum@plt>
lea    0xe71(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 16)
%2 = inttoptr i64 %1 to i32**
%3 = tail call i64 @malloc(i32 8)
%4 = inttoptr i64 %3 to i32*
store i32* %4, i32** %2
%5 = tail call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i32*
%7 = getelementptr inbounds i32*, i32** %2, i64 1
store i32* %6, i32** %7
%8 = load i32*, i32** %2
store i32 1, i32* %8
%9 = getelementptr inbounds i32, i32* %8, i64 1
store i32 2, i32* %9
store i32 1, i32* %6
%10 = getelementptr inbounds i32, i32* %6, i64 1
store i32 1, i32* %10
%11 = tail call i32 @minPathSum(i32** %2, i32 2, i32 2)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %11)
ret i32 0
}