#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 /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  char *ch1 = "hello there buddy what is going on";
  int i;
  int dim1 = 10;
  int dim2 = 40;
  char **temp_buf = malloc(dim1 * sizeof(char *));
  for (int i = 0; i < dim1; ++i) {
    temp_buf[i] = malloc(dim2);
  }
  for (i = 0; i < 10; ++i) {
    memcpy(temp_buf[i], ch1, 35);
  }
  for (i = 0; i < 10; ++i) {
    printf("%s\n", temp_buf[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0xa,-0x20(%rbp)
movl   $0x28,-0x24(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11aa <main+0x7a>
mov    -0x24(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1179 <main+0x49>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11e3 <main+0xb3>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b1 <main+0x81>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    121a <main+0xea>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ea <main+0xba>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x30(%rsp)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x10(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x18(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x20(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x28(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x30(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x38(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,0x40(%rbx)
mov    $0x28,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0xe1f(%rip),%r14
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x8(%rbx),%rdi
mov    %rdi,0x28(%rsp)
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x10(%rbx),%rdi
mov    %rdi,0x20(%rsp)
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x18(%rbx),%rdi
mov    %rdi,0x18(%rsp)
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x20(%rbx),%rdi
mov    %rdi,0x10(%rsp)
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x28(%rbx),%rdi
mov    %rdi,0x8(%rsp)
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x30(%rbx),%r13
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x38(%rbx),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    0x40(%rbx),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x23,%edx
call   1040 <memcpy@plt>
lea    0xd71(%rip),%rbp
mov    %rbp,%rdi
mov    0x30(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    0x28(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    0x20(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    0x18(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [35 x i8] c"hello there buddy what is going on\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%4 = bitcast i8* %3 to i8**
%5 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%6 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%7 = getelementptr inbounds i8*, i8** %4, i64 1
store i8* %6, i8** %7
%8 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%9 = getelementptr inbounds i8*, i8** %4, i64 2
store i8* %8, i8** %9
%10 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%11 = getelementptr inbounds i8*, i8** %4, i64 3
store i8* %10, i8** %11
%12 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%13 = getelementptr inbounds i8*, i8** %4, i64 4
store i8* %12, i8** %13
%14 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%15 = getelementptr inbounds i8*, i8** %4, i64 5
store i8* %14, i8** %15
%16 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%17 = getelementptr inbounds i8*, i8** %4, i64 6
store i8* %16, i8** %17
%18 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%19 = getelementptr inbounds i8*, i8** %4, i64 7
store i8* %18, i8** %19
%20 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%21 = getelementptr inbounds i8*, i8** %4, i64 8
store i8* %20, i8** %21
%22 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%23 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%24 = load i8*, i8** %7
%25 = tail call i32 @memcpy(i8* %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%26 = load i8*, i8** %9
%27 = tail call i32 @memcpy(i8* %26, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%28 = load i8*, i8** %11
%29 = tail call i32 @memcpy(i8* %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%30 = load i8*, i8** %13
%31 = tail call i32 @memcpy(i8* %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%32 = load i8*, i8** %15
%33 = tail call i32 @memcpy(i8* %32, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%34 = load i8*, i8** %17
%35 = tail call i32 @memcpy(i8* %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%36 = load i8*, i8** %19
%37 = tail call i32 @memcpy(i8* %36, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%38 = load i8*, i8** %21
%39 = tail call i32 @memcpy(i8* %38, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%40 = tail call i32 @memcpy(i8* %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 35)
%41 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%42 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%43 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%44 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%45 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%46 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%47 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%48 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%49 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %38)
%50 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
ret i32 0
}