#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 */
void *malloc(int);
int **make_backup(int **grid) {
  int **backup;
  int i;
  int j;
  backup = malloc(sizeof(int *) * 9);
  i = -1;
  while (++i < 9) {
    j = -1;
    backup[i] = malloc(sizeof(int) * 9);
    while (++j < 9)
      backup[i][j] = grid[i][j];
  }
  return (backup);
}


x86 assembly (clang, -O0):
<make_backup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x9,%eax
jge    11a5 <make_backup+0x95>
movl   $0xffffffff,-0x18(%rbp)
mov    $0x24,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmp    $0x9,%eax
jge    11a0 <make_backup+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1163 <make_backup+0x53>
jmp    1131 <make_backup+0x21>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_backup>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x24,%edi
call   1030 <malloc@plt>
mov    %rax,(%r15,%rbx,8)
mov    (%r14,%rbx,8),%rcx
mov    (%rcx),%edx
mov    %edx,(%rax)
mov    0x4(%rcx),%edx
mov    %edx,0x4(%rax)
mov    0x8(%rcx),%edx
mov    %edx,0x8(%rax)
mov    0xc(%rcx),%edx
mov    %edx,0xc(%rax)
mov    0x10(%rcx),%edx
mov    %edx,0x10(%rax)
mov    0x14(%rcx),%edx
mov    %edx,0x14(%rax)
mov    0x18(%rcx),%edx
mov    %edx,0x18(%rax)
mov    0x1c(%rcx),%edx
mov    %edx,0x1c(%rax)
mov    0x20(%rcx),%ecx
mov    %ecx,0x20(%rax)
add    $0x1,%rbx
cmp    $0x9,%rbx
jne    1130 <make_backup+0x20>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32** @make_backup(i32** %0) {
%2 = alloca i32**
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
store i32** %0, i32*** %2
%6 = call i8* @malloc(i32 72)
%7 = bitcast i8* %6 to i32**
store i32** %7, i32*** %3
store i32 -1, i32* %4
br label %8
8: ; preds = %41, %1
%9 = load i32, i32* %4
%10 = add nsw i32 %9, 1
store i32 %10, i32* %4
%11 = icmp slt i32 %10, 9
br i1 %11, label %12, label %42
12: ; preds = %8
store i32 -1, i32* %5
%13 = call i8* @malloc(i32 36)
%14 = bitcast i8* %13 to i32*
%15 = load i32**, i32*** %3
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32*, i32** %15, i64 %17
store i32* %14, i32** %18
br label %19
19: ; preds = %23, %12
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = icmp slt i32 %21, 9
br i1 %22, label %23, label %41
23: ; preds = %19
%24 = load i32**, i32*** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32*, i32** %24, i64 %26
%28 = load i32*, i32** %27
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32**, i32*** %3
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32*, i32** %33, i64 %35
%37 = load i32*, i32** %36
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %32, i32* %40
br label %19
41: ; preds = %19
br label %8
42: ; preds = %8
%43 = load i32**, i32*** %3
ret i32** %43
}

LLVM IR (-O2):
define noalias i32** @make_backup(i32** nocapture %0) {
%2 = tail call dereferenceable_or_null(72) i8* @malloc(i32 72)
%3 = bitcast i8* %2 to i32**
br label %4
4: ; preds = %1, %4
%5 = phi i64 [ 0, %1 ], [ %37, %4 ]
%6 = tail call dereferenceable_or_null(36) i8* @malloc(i32 36)
%7 = getelementptr inbounds i32*, i32** %3, i64 %5
%8 = bitcast i32** %7 to i8**
store i8* %6, i8** %8
%9 = getelementptr inbounds i32*, i32** %0, i64 %5
%10 = load i32*, i32** %9
%11 = bitcast i8* %6 to i32*
%12 = load i32, i32* %10
store i32 %12, i32* %11
%13 = getelementptr inbounds i32, i32* %10, i64 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds i32, i32* %11, i64 1
store i32 %14, i32* %15
%16 = getelementptr inbounds i32, i32* %10, i64 2
%17 = load i32, i32* %16
%18 = getelementptr inbounds i32, i32* %11, i64 2
store i32 %17, i32* %18
%19 = getelementptr inbounds i32, i32* %10, i64 3
%20 = load i32, i32* %19
%21 = getelementptr inbounds i32, i32* %11, i64 3
store i32 %20, i32* %21
%22 = getelementptr inbounds i32, i32* %10, i64 4
%23 = load i32, i32* %22
%24 = getelementptr inbounds i32, i32* %11, i64 4
store i32 %23, i32* %24
%25 = getelementptr inbounds i32, i32* %10, i64 5
%26 = load i32, i32* %25
%27 = getelementptr inbounds i32, i32* %11, i64 5
store i32 %26, i32* %27
%28 = getelementptr inbounds i32, i32* %10, i64 6
%29 = load i32, i32* %28
%30 = getelementptr inbounds i32, i32* %11, i64 6
store i32 %29, i32* %30
%31 = getelementptr inbounds i32, i32* %10, i64 7
%32 = load i32, i32* %31
%33 = getelementptr inbounds i32, i32* %11, i64 7
store i32 %32, i32* %33
%34 = getelementptr inbounds i32, i32* %10, i64 8
%35 = load i32, i32* %34
%36 = getelementptr inbounds i32, i32* %11, i64 8
store i32 %35, i32* %36
%37 = add nuw nsw i64 %5, 1
%38 = icmp eq i64 %37, 9
br i1 %38, label %39, label %4
39: ; preds = %4
ret i32** %3
}