#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 dump_pgm(unsigned char *ptr, int rowstride, int width, int height) {
  int x, y;
  printf("P2\n");
  printf("%d %d\n", width, height);
  printf("255\n");
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
      printf("%d ", ptr[x]);
      if ((x & 15) == 15) {
        printf("\n");
      }
    }
    printf("\n");
    ptr += rowstride;
  }
}


x86 assembly (clang, -O0):
<dump_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    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f2 <dump_pgm+0xe2>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c5 <dump_pgm+0xb5>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    11b2 <dump_pgm+0xa2>
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b7 <dump_pgm+0xa7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116f <dump_pgm+0x5f>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <dump_pgm+0x4c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_pgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbp
lea    0xebe(%rip),%rdi
call   1040 <puts@plt>
lea    0xea7(%rip),%rdi
mov    %r15d,(%rsp)
mov    %r15d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
jle    11ee <dump_pgm+0xbe>
movslq %r14d,%r12
mov    (%rsp),%ebx
lea    0xe7d(%rip),%r13
xor    %r14d,%r14d
jmp    11a8 <dump_pgm+0x78>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    %r12,%rbp
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
je     11ee <dump_pgm+0xbe>
cmpl   $0x0,(%rsp)
jle    1190 <dump_pgm+0x60>
xor    %r15d,%r15d
jmp    11c9 <dump_pgm+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15
cmp    %r15,%rbx
je     1190 <dump_pgm+0x60>
movzbl 0x0(%rbp,%r15,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
not    %eax
test   $0xf,%al
jne    11c0 <dump_pgm+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <dump_pgm+0x90>
add    $0x8,%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 = [7 x i8] c"%d %d\0A\00"
@.str.2 = [5 x i8] c"255\0A\00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [2 x i8] c"\0A\00"
define void @dump_pgm(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
store i8* %0, i8** %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* %7
%13 = load i32, i32* %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %10
br label %16
16: ; preds = %48, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %8
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %51
20: ; preds = %16
store i32 0, i32* %9
br label %21
21: ; preds = %39, %20
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %9
%34 = and i32 %33, 15
%35 = icmp eq i32 %34, 15
br i1 %35, label %36, label %38
36: ; preds = %25
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %36, %25
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %21
42: ; preds = %21
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = load i8*, i8** %5
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %45, i64 %46
store i8* %47, i8** %5
br label %48
48: ; preds = %42
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %16
51: ; preds = %16
ret void
}

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