#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*/ *);
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int hexdump(FILE *fo, FILE *fi) {
  int c, n;
  n = 0;
  c = fgetc(fi);
  while (c != -1) {
    n += fprintf(fo, "%d,", c);
    if (n > 72) {
      fprintf(fo, "\n");
      n = 0;
    }
    c = fgetc(fi);
  }
  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     11a3 <hexdump+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    %rax,%rcx
movslq -0x18(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x18(%rbp)
cmpl   $0x48,-0x18(%rbp)
jle    1192 <hexdump+0x72>
mov    -0x8(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x14(%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   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <fgetc@plt>
cmp    $0xffffffff,%eax
je     1199 <hexdump+0x69>
lea    0xeae(%rip),%r15
xor    %ebp,%ebp
jmp    116f <hexdump+0x3f>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <fgetc@plt>
mov    %ebx,%ebp
cmp    $0xffffffff,%eax
je     119b <hexdump+0x6b>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rax,%rbx
add    %ebp,%ebx
cmp    $0x49,%ebx
jl     1160 <hexdump+0x30>
mov    $0xa,%edi
mov    %r12,%rsi
call   1040 <fputc@plt>
xor    %ebx,%ebx
jmp    1160 <hexdump+0x30>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d,\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 = %25, %2
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, -1
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i32*, i32** %3
%14 = load i32, i32* %5
%15 = call i64 (i32*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = add nsw i64 %17, %15
%19 = trunc i64 %18 to i32
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sgt i32 %20, 72
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32*, i32** %3
%24 = call i64 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %25
25: ; preds = %22, %12
%26 = load i32*, i32** %4
%27 = call i32 @fgetc(i32* %26)
store i32 %27, i32* %5
br label %9
28: ; preds = %9
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d,\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 %18, label %5
5: ; preds = %2, %14
%6 = phi i32 [ %15, %14 ], [ 0, %2 ]
%7 = phi i32 [ %16, %14 ], [ %3, %2 ]
%8 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = trunc i64 %8 to i32
%10 = add i32 %6, %9
%11 = icmp sgt i32 %10, 72
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @fputc(i32 10, i32* %0)
br label %14
14: ; preds = %12, %5
%15 = phi i32 [ 0, %12 ], [ %10, %5 ]
%16 = tail call i32 @fgetc(i32* %1)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %5
18: ; preds = %14, %2
%19 = phi i32 [ 0, %2 ], [ %15, %14 ]
ret i32 %19
}