#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int save_page(FILE *out, unsigned char *page) {
  int i, column = 0;
  for (i = 0; i < 256; i++) {
    if (column >= 40) {
      fprintf(out, "\n");
      column = 0;
    }
    fprintf(out, "%02x", *page);
    column++;
    page++;
  }
  fprintf(out, "\n");
  return 1;
}


x86 assembly (clang, -O0):
<save_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    119a <save_page+0x8a>
cmpl   $0x28,-0x18(%rbp)
jl     115e <save_page+0x4e>
mov    -0x8(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movzbl (%rax),%edx
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <save_page+0x1e>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_page>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xecb(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1161 <save_page+0x41>
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edx
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebp
add    $0x1,%rbx
cmp    $0x100,%ebx
je     1177 <save_page+0x57>
cmp    $0x28,%ebp
jl     1140 <save_page+0x20>
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
xor    %ebp,%ebp
jmp    1140 <save_page+0x20>
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [5 x i8] c"%02x\00"
define i32 @save_page(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %26, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 256
br i1 %9, label %10, label %29
10: ; preds = %7
%11 = load i32, i32* %6
%12 = icmp sge i32 %11, 40
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %16
16: ; preds = %13, %10
%17 = load i32*, i32** %3
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %26
26: ; preds = %16
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %7
29: ; preds = %7
%30 = load i32*, i32** %3
%31 = call i32 (i32*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%02x\00"
define i32 @save_page(i32* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %2, %10
%4 = phi i32 [ 0, %2 ], [ %15, %10 ]
%5 = phi i32 [ 0, %2 ], [ %17, %10 ]
%6 = phi i8* [ %1, %2 ], [ %16, %10 ]
%7 = icmp sgt i32 %4, 39
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @fputc(i32 10, i32* %0)
br label %10
10: ; preds = %8, %3
%11 = phi i32 [ 0, %8 ], [ %4, %3 ]
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = add nsw i32 %11, 1
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = add nuw nsw i32 %5, 1
%18 = icmp eq i32 %17, 256
br i1 %18, label %19, label %3
19: ; preds = %10
%20 = tail call i32 @fputc(i32 10, i32* %0)
ret i32 1
}