#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char **argv) {
  char a[255];
  FILE *fi, *fo;
  int i = 0;
  sprintf(a, "%s.txt", argv[1]);
  fi = fopen(argv[1], "rb");
  fo = fopen(a, "w");
  while (!feof(fi)) {
    i++;
    fread(a, 1, 1, fi);
    fprintf(fo, "%c=%02x ", (*a >= 32) ? *a : '.', (unsigned char)(*a));
    fprintf(fo, "\n");
    if (i > 5000)
      break;
  }
  fclose(fi);
  fclose(fo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x124(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe67(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x120(%rbp)
mov    -0x118(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f4 <main+0x94>
jmp    12ae <main+0x14e>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
movsbl -0x110(%rbp),%eax
cmp    $0x20,%eax
jl     124d <main+0xed>
movsbl -0x110(%rbp),%eax
mov    %eax,-0x134(%rbp)
jmp    125d <main+0xfd>
mov    $0x2e,%eax
mov    %eax,-0x134(%rbp)
jmp    125d <main+0xfd>
mov    -0x130(%rbp),%rdi
mov    -0x134(%rbp),%edx
movzbl -0x110(%rbp),%ecx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x120(%rbp),%rdi
lea    0xd88(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x1388,-0x124(%rbp)
jle    12a9 <main+0x149>
jmp    12ae <main+0x14e>
jmp    11d3 <main+0x73>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x120(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdx
lea    0xe73(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1090 <sprintf@plt>
mov    0x8(%rbx),%rdi
lea    0xe64(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r15
lea    0xe58(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    $0x1389,%ebp
lea    0xe43(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    121f <main+0xaf>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
movzbl (%rsp),%ecx
cmp    $0x20,%cl
mov    $0x2e,%edx
cmovge %ecx,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    11d0 <main+0x60>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"%c=%02x \00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %8
br label %21
21: ; preds = %53, %2
%22 = load i32*, i32** %7
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %54
26: ; preds = %21
%27 = load i32, i32* %9
%28 = add nsw i32 %27, 1
store i32 %28, i32* %9
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%30 = load i32*, i32** %7
%31 = call i32 @fread(i8* %29, i32 1, i32 1, i32* %30)
%32 = load i32*, i32** %8
%33 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp sge i32 %35, 32
br i1 %36, label %37, label %41
37: ; preds = %26
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
br label %42
41: ; preds = %26
br label %42
42: ; preds = %41, %37
%43 = phi i32 [ %40, %37 ], [ 46, %41 ]
%44 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %46)
%48 = load i32*, i32** %8
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* %9
%51 = icmp sgt i32 %50, 5000
br i1 %51, label %52, label %53
52: ; preds = %42
br label %54
53: ; preds = %42
br label %21
54: ; preds = %52, %21
%55 = load i32*, i32** %7
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %8
%58 = call i32 @fclose(i32* %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s.txt\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [9 x i8] c"%c=%02x \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %5
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %15, %2
%12 = phi i32 [ 0, %2 ], [ %16, %15 ]
%13 = tail call i32 @feof(i32* %9)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = add nuw nsw i32 %12, 1
%17 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %9)
%18 = load i8, i8* %4
%19 = icmp sgt i8 %18, 31
%20 = select i1 %19, i8 %18, i8 46
%21 = zext i8 %20 to i32
%22 = zext i8 %18 to i32
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
%24 = tail call i32 @fputc(i32 10, i32* %10)
%25 = icmp eq i32 %16, 5001
br i1 %25, label %26, label %11
26: ; preds = %15, %11
%27 = tail call i32 @fclose(i32* %9)
%28 = tail call i32 @fclose(i32* %10)
ret i32 0
}