#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 escrever_pgm(int img[][400], int W, int H, int MaxV) {
  int i, j;
  printf("P2\n");
  printf("%d %d %d\n", W, H, MaxV);
  for (i = 0; i < H; i++) {
    printf("%d", img[i][0]);
    for (j = 1; j < W; j++) {
      printf(" %d", img[i][j]);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<escrever_pgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e3 <escrever_pgm+0xd3>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x640,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c7 <escrever_pgm+0xb7>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
imul   $0x640,%rcx,%rcx
add    %rcx,%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1186 <escrever_pgm+0x76>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1151 <escrever_pgm+0x41>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escrever_pgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,0x10(%rsp)
lea    0xebd(%rip),%rdi
call   1040 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %ebp,0xc(%rsp)
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
test   %ebx,%ebx
jle    11f9 <escrever_pgm+0xc9>
mov    %ebx,%r13d
mov    0xc(%rsp),%ebp
lea    0xe85(%rip),%rbx
mov    0x10(%rsp),%r14
xor    %r15d,%r15d
jmp    11aa <escrever_pgm+0x7a>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
add    $0x640,%r14
cmp    %r13,%r15
je     11f9 <escrever_pgm+0xc9>
imul   $0x640,%r15,%rax
mov    0x10(%rsp),%rcx
mov    (%rcx,%rax,1),%esi
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x2,0xc(%rsp)
jl     1190 <escrever_pgm+0x60>
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%r12,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    11e0 <escrever_pgm+0xb0>
jmp    1190 <escrever_pgm+0x60>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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