#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 /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int *image3d;
  int wartosc = 0;
  int length = 3 * 5 * 6;
  image3d = (int *)malloc(sizeof(int) * length);
  int i;
  int *ptr;
  ptr = image3d;
  for (i = 0; i < length; i++) {
    *ptr = wartosc++;
    ptr++;
    if (i == 29) {
      wartosc = 100;
    } else if (i == 59) {
      wartosc = 1000;
    }
  }
  for (i = 0; i < length; i++) {
    if (i % 10 == 0) {
      printf("\n");
    }
    printf("%d ", *(image3d + i));
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x5a,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c7 <main+0xa7>
mov    -0x14(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1d,-0x1c(%rbp)
jne    119e <main+0x7e>
movl   $0x64,-0x14(%rbp)
jmp    11b4 <main+0x94>
cmpl   $0x3b,-0x1c(%rbp)
jne    11af <main+0x8f>
movl   $0x3e8,-0x14(%rbp)
jmp    11b4 <main+0x94>
jmp    11b9 <main+0x99>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <main+0x3f>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1223 <main+0x103>
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11fc <main+0xdc>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <main+0xae>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x168,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %eax,%eax
mov    $0x3e8,%ecx
mov    $0x64,%edx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %esi,(%r15,%rax,4)
add    $0x1,%esi
cmp    $0x3b,%eax
cmove  %ecx,%esi
cmp    $0x1d,%eax
cmove  %edx,%esi
mov    %esi,0x4(%r15,%rax,4)
lea    0x1(%rax),%edi
add    $0x1,%esi
cmp    $0x3b,%edi
cmove  %ecx,%esi
cmp    $0x1d,%edi
cmove  %edx,%esi
mov    %esi,0x8(%r15,%rax,4)
lea    0x2(%rax),%edi
add    $0x1,%esi
cmp    $0x3b,%edi
cmove  %ecx,%esi
cmp    $0x1d,%edi
cmove  %edx,%esi
add    $0x3,%rax
cmp    $0x5a,%eax
jne    1160 <main+0x30>
lea    0xe4f(%rip),%r14
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    11dc <main+0xac>
nopl   0x0(%rax,%rax,1)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
add    $0xff,%r12b
cmp    $0x5a,%rbx
je     11ff <main+0xcf>
movzbl %bl,%eax
imul   $0xcd,%eax,%eax
shr    $0xa,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rax,4),%eax
add    %r12b,%al
jne    11c0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 360)
%2 = inttoptr i64 %1 to i32*
br label %3
3: ; preds = %3, %0
%4 = phi i32* [ %2, %0 ], [ %21, %3 ]
%5 = phi i32 [ 0, %0 ], [ %27, %3 ]
%6 = phi i32 [ 0, %0 ], [ %26, %3 ]
store i32 %6, i32* %4
%7 = getelementptr inbounds i32, i32* %4, i64 1
%8 = icmp eq i32 %5, 29
%9 = add nsw i32 %6, 1
%10 = icmp eq i32 %5, 59
%11 = select i1 %10, i32 1000, i32 %9
%12 = select i1 %8, i32 100, i32 %11
%13 = add nuw nsw i32 %5, 1
store i32 %12, i32* %7
%14 = getelementptr inbounds i32, i32* %4, i64 2
%15 = icmp eq i32 %13, 29
%16 = add nsw i32 %12, 1
%17 = icmp eq i32 %13, 59
%18 = select i1 %17, i32 1000, i32 %16
%19 = select i1 %15, i32 100, i32 %18
%20 = add nuw nsw i32 %5, 2
store i32 %19, i32* %14
%21 = getelementptr inbounds i32, i32* %4, i64 3
%22 = icmp eq i32 %20, 29
%23 = add nsw i32 %19, 1
%24 = icmp eq i32 %20, 59
%25 = select i1 %24, i32 1000, i32 %23
%26 = select i1 %22, i32 100, i32 %25
%27 = add nuw nsw i32 %5, 3
%28 = icmp eq i32 %27, 90
br i1 %28, label %29, label %3
29: ; preds = %3, %36
%30 = phi i64 [ %40, %36 ], [ 0, %3 ]
%31 = trunc i64 %30 to i8
%32 = urem i8 %31, 10
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = tail call i32 @putchar(i32 10)
br label %36
36: ; preds = %34, %29
%37 = getelementptr inbounds i32, i32* %2, i64 %30
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = add nuw nsw i64 %30, 1
%41 = icmp eq i64 %40, 90
br i1 %41, label %42, label %29
42: ; preds = %36
%43 = tail call i32 @putchar(i32 10)
ret i32 0
}