#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 EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintRTF(char *, ...);
void PutHexFile(FILE *fp) {
  int i, c;
  i = 0;
  while ((c = fgetc(fp)) != EOF) {
    fprintRTF("%.2x", c);
    if (++i > 126) {
      i = 0;
      fprintRTF("\n");
    }
  }
}


x86 assembly (clang, -O0):
<PutHexFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x10(%rbp)
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
je     118b <PutHexFile+0x6b>
mov    -0x10(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <fprintRTF@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x7e,%eax
jle    1186 <PutHexFile+0x66>
movl   $0x0,-0xc(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <fprintRTF@plt>
jmp    1133 <PutHexFile+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PutHexFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1030 <fgetc@plt>
mov    0x2eb1(%rip),%r12
cmp    (%r12),%eax
jne    1146 <PutHexFile+0x26>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeb3(%rip),%r14
lea    0xeb1(%rip),%r15
xor    %ebp,%ebp
jmp    117a <PutHexFile+0x5a>
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <fprintRTF@plt>
mov    %rbx,%rdi
call   1030 <fgetc@plt>
cmp    (%r12),%eax
je     113d <PutHexFile+0x1d>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <fprintRTF@plt>
cmp    $0x7e,%ebp
jge    1160 <PutHexFile+0x40>
add    $0x1,%ebp
jmp    116c <PutHexFile+0x4c>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [5 x i8] c"%.2x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @PutHexFile(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %3
br label %5
5: ; preds = %18, %1
%6 = load i32*, i32** %2
%7 = call i32 @fgetc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i32, i32* %4
%12 = call i32 (i8*, ...) @fprintRTF(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = icmp sgt i32 %14, 126
br i1 %15, label %16, label %18
16: ; preds = %10
store i32 0, i32* %3
%17 = call i32 (i8*, ...) @fprintRTF(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
br label %5
19: ; preds = %5
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [5 x i8] c"%.2x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @PutHexFile(i32* nocapture %0) {
%2 = tail call i32 @fgetc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %18, label %5
5: ; preds = %1, %13
%6 = phi i32 [ %15, %13 ], [ %2, %1 ]
%7 = phi i32 [ %14, %13 ], [ 0, %1 ]
%8 = tail call i32 (i8*, ...) @fprintRTF(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%9 = add nsw i32 %7, 1
%10 = icmp sgt i32 %7, 125
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = tail call i32 (i8*, ...) @fprintRTF(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %5
%14 = phi i32 [ 0, %11 ], [ %9, %5 ]
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %5
18: ; preds = %13, %1
ret void
}