#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int hexdump(FILE *fo, FILE *fi) {
  int c, n;
  n = 0;
  c = fgetc(fi);
  while (c != -1) {
    fprintf(fo, "0x%02x,", c);
    if (n % 16 == 15)
      fprintf(fo, "\n");
    c = fgetc(fi);
    n++;
  }
  return n;
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
je     11a2 <hexdump+0x82>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    1188 <hexdump+0x68>
mov    -0x8(%rbp),%rdi
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1143 <hexdump+0x23>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <fgetc@plt>
cmp    $0xffffffff,%eax
je     1196 <hexdump+0x66>
lea    0xeaf(%rip),%r15
xor    %ebp,%ebp
jmp    1170 <hexdump+0x40>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <fgetc@plt>
add    $0x1,%ebp
cmp    $0xffffffff,%eax
je     1198 <hexdump+0x68>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
not    %eax
test   $0xf,%al
jne    1160 <hexdump+0x30>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    1160 <hexdump+0x30>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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