#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*/ printf(char *, ...);
void print_buffer(const char *name, int *buffer, int m, int n) {
  int j;
  printf("%s\n", name);
  for (j = 0; j < m; ++j) {
    int i;
    int *buffer_m = buffer + n * j;
    for (i = 0; i < n - 1; ++i)
      printf("%d ", buffer_m[i]);
    if (n > 0)
      printf("%d\n", buffer_m[n - 1]);
  }
}


x86 assembly (clang, -O0):
<print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11de <print_buffer+0xce>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a3 <print_buffer+0x93>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116b <print_buffer+0x5b>
cmpl   $0x0,-0x18(%rbp)
jle    11cb <print_buffer+0xbb>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <print_buffer+0xc0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113f <print_buffer+0x2f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,0x8(%rsp)
call   1030 <puts@plt>
test   %r12d,%r12d
jle    11e2 <print_buffer+0xc2>
lea    -0x1(%r15),%ebx
movslq %r15d,%rax
mov    %r12d,%ecx
mov    %rcx,0x20(%rsp)
mov    %rax,0x10(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x18(%rsp)
lea    0xe91(%rip),%r13
mov    0x8(%rsp),%rbp
xor    %r12d,%r12d
jmp    1190 <print_buffer+0x70>
nopl   0x0(%rax)
add    $0x1,%r12
add    0x18(%rsp),%rbp
cmp    0x20(%rsp),%r12
je     11e2 <print_buffer+0xc2>
cmp    $0x2,%r15d
jl     11b8 <print_buffer+0x98>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    0x0(%rbp,%r14,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
jne    11a0 <print_buffer+0x80>
test   %r15d,%r15d
jle    1180 <print_buffer+0x60>
mov    %r12,%rax
imul   0x10(%rsp),%rax
mov    0x8(%rsp),%rcx
lea    (%rcx,%rax,4),%rax
mov    (%rax,%rbx,4),%esi
lea    0xe2b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <print_buffer+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @print_buffer(i8* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = tail call i32 @puts(i8* dereferenceable(1) %0)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %33
7: ; preds = %4
%8 = add i32 %3, -1
%9 = icmp sgt i32 %3, 1
%10 = icmp sgt i32 %3, 0
%11 = zext i32 %8 to i64
%12 = sext i32 %3 to i64
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %7, %30
%15 = phi i64 [ 0, %7 ], [ %31, %30 ]
%16 = mul nsw i64 %15, %12
%17 = getelementptr inbounds i32, i32* %1, i64 %16
br i1 %9, label %18, label %25
18: ; preds = %14, %18
%19 = phi i64 [ %23, %18 ], [ 0, %14 ]
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, %11
br i1 %24, label %25, label %18
25: ; preds = %18, %14
br i1 %10, label %26, label %30
26: ; preds = %25
%27 = getelementptr inbounds i32, i32* %17, i64 %11
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %25
%31 = add nuw nsw i64 %15, 1
%32 = icmp eq i64 %31, %13
br i1 %32, label %33, label %14
33: ; preds = %30, %4
ret void
}