#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 */
int /*<<< orphan*/ getchar();
int **malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  unsigned int x = 1;
  double y;
  struct t {
    char c;
  };
  int a[3][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}};
  int rows = 1;
  int columns = 2;
  int start = 1;
  int i, j;
  int **b = NULL;
  b = malloc(sizeof(*b) * rows + (rows * columns * sizeof(**b)));
  printf("sizeof(*b)=%ld sizeof(**b)=%ld total size %ld\n", sizeof(*b),
         sizeof(**b), (sizeof(*b) * rows + (rows * columns * sizeof(**b))));
  printf("%ld\n", (char *)(&y + 1) - (char *)(&y));
  getchar();
  for (i = 0; i < rows; i++) {
    for (j = 0; j < columns; j++) {
      printf("Copying b[%d][%d]\n", i, j);
      b[i][j] = start++;
    }
    start += 10;
  }
  printf("Printing Two Dimensional array with %d rows and %d columns\n", rows,
         columns);
  for (i = 0; i < rows; i++) {
    for (j = 0; j < columns; j++) {
      printf("%d ", b[i][j]);
    }
    printf("\n");
    start += 10;
  }
  printf("%d\n", (int)(((char *)&x)[0]));
  printf("Must print 1 if you have machine which is Little Endian\n");
  printf("size of struct t %ld\n", sizeof(struct t));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x30,%edx
call   1050 <memcpy@plt>
movl   $0x1,-0x44(%rbp)
movl   $0x2,-0x48(%rbp)
movl   $0x1,-0x4c(%rbp)
movq   $0x0,-0x60(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x3,%rax
mov    -0x44(%rbp),%ecx
imul   -0x48(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x60(%rbp)
movslq -0x44(%rbp),%rcx
shl    $0x3,%rcx
mov    -0x44(%rbp),%eax
imul   -0x48(%rbp),%eax
cltq
shl    $0x2,%rax
add    %rax,%rcx
lea    0xe65(%rip),%rdi
mov    $0x8,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rsi
add    $0x8,%rsi
lea    -0x10(%rbp),%rax
sub    %rax,%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    127d <main+0x13d>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    1266 <main+0x126>
mov    -0x50(%rbp),%esi
mov    -0x54(%rbp),%edx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x60(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x54(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    121a <main+0xda>
mov    -0x4c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1207 <main+0xc7>
mov    -0x44(%rbp),%esi
mov    -0x48(%rbp),%edx
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    130b <main+0x1cb>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x48(%rbp),%eax
jge    12e6 <main+0x1a6>
mov    -0x60(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12ab <main+0x16b>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4c(%rbp),%eax
add    $0xa,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    1298 <main+0x158>
movsbl -0x8(%rbp),%esi
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdbd(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x10,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe97(%rip),%rdi
mov    $0x8,%esi
mov    $0x4,%edx
mov    $0x10,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
lea    0xe8f(%rip),%r15
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r14),%rbx
movl   $0x1,(%rbx)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1050 <printf@plt>
movl   $0x2,0x4(%rbx)
lea    0xe6c(%rip),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
lea    0xe8e(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6a(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4f(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.a = [3 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], [4 x i32] [i32 4, i32 5, i32 6, i32 7], [4 x i32] [i32 8, i32 9, i32 10, i32 11]]
@.str = [47 x i8] c"sizeof(*b)=%ld sizeof(**b)=%ld total size %ld\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [19 x i8] c"Copying b[%d][%d]\0A\00"
@.str.3 = [60 x i8] c"Printing Two Dimensional array with %d rows and %d columns\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [57 x i8] c"Must print 1 if you have machine which is Little Endian\0A\00"
@.str.8 = [22 x i8] c"size of struct t %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca [3 x [4 x i32]]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32**
store i32 0, i32* %1
store i32 1, i32* %2
%11 = bitcast [3 x [4 x i32]]* %4 to i8*
store i32 1, i32* %5
store i32 2, i32* %6
store i32 1, i32* %7
store i32** null, i32*** %10
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 8, %13
%15 = load i32, i32* %5
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 4
%20 = add i64 %14, %19
%21 = trunc i64 %20 to i32
%22 = call i32** @malloc(i32 %21)
store i32** %22, i32*** %10
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul i64 8, %24
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = mul nsw i32 %26, %27
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 4
%31 = add i64 %25, %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 8, i64 4, i64 %31)
%33 = getelementptr inbounds double, double* %3, i64 1
%34 = bitcast double* %33 to i8*
%35 = bitcast double* %3 to i8*
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %38)
%40 = call i32 (...) @getchar()
store i32 0, i32* %8
br label %41
41: ; preds = %70, %0
%42 = load i32, i32* %8
%43 = load i32, i32* %5
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %73
45: ; preds = %41
store i32 0, i32* %9
br label %46
46: ; preds = %64, %45
%47 = load i32, i32* %9
%48 = load i32, i32* %6
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %67
50: ; preds = %46
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %51, i32 %52)
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
%56 = load i32**, i32*** %10
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32*, i32** %56, i64 %58
%60 = load i32*, i32** %59
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32, i32* %60, i64 %62
store i32 %54, i32* %63
br label %64
64: ; preds = %50
%65 = load i32, i32* %9
%66 = add nsw i32 %65, 1
store i32 %66, i32* %9
br label %46
67: ; preds = %46
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 10
store i32 %69, i32* %7
br label %70
70: ; preds = %67
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 1
store i32 %72, i32* %8
br label %41
73: ; preds = %41
%74 = load i32, i32* %5
%75 = load i32, i32* %6
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 %74, i32 %75)
store i32 0, i32* %8
br label %77
77: ; preds = %104, %73
%78 = load i32, i32* %8
%79 = load i32, i32* %5
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %107
81: ; preds = %77
store i32 0, i32* %9
br label %82
82: ; preds = %97, %81
%83 = load i32, i32* %9
%84 = load i32, i32* %6
%85 = icmp slt i32 %83, %84
br i1 %85, label %86, label %100
86: ; preds = %82
%87 = load i32**, i32*** %10
%88 = load i32, i32* %8
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i32*, i32** %87, i64 %89
%91 = load i32*, i32** %90
%92 = load i32, i32* %9
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i32, i32* %91, i64 %93
%95 = load i32, i32* %94
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %95)
br label %97
97: ; preds = %86
%98 = load i32, i32* %9
%99 = add nsw i32 %98, 1
store i32 %99, i32* %9
br label %82
100: ; preds = %82
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%102 = load i32, i32* %7
%103 = add nsw i32 %102, 10
store i32 %103, i32* %7
br label %104
104: ; preds = %100
%105 = load i32, i32* %8
%106 = add nsw i32 %105, 1
store i32 %106, i32* %8
br label %77
107: ; preds = %77
%108 = bitcast i32* %2 to i8*
%109 = getelementptr inbounds i8, i8* %108, i64 0
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %111)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.7, i64 0, i64 0))
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i64 1)
ret i32 0
}

LLVM IR (-O2):
@.str = [47 x i8] c"sizeof(*b)=%ld sizeof(**b)=%ld total size %ld\0A\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
@.str.2 = [19 x i8] c"Copying b[%d][%d]\0A\00"
@.str.3 = [60 x i8] c"Printing Two Dimensional array with %d rows and %d columns\0A\00"
@.str.4 = [4 x i8] c"%d \00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.8 = [22 x i8] c"size of struct t %ld\0A\00"
@str = [56 x i8] c"Must print 1 if you have machine which is Little Endian\00"
define i32 @main() {
%1 = tail call i32** @malloc(i32 16)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i64 8, i64 4, i64 16)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 8)
%4 = tail call i32 (...) @getchar()
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0)
%6 = load i32*, i32** %1
store i32 1, i32* %6
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 1)
%8 = getelementptr inbounds i32, i32* %6, i64 1
store i32 2, i32* %8
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i32 1, i32 2)
%10 = load i32, i32* %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %8
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = tail call i32 @putchar(i32 10)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 1)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i64 1)
ret i32 0
}