#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
unsigned char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, unsigned char);
int main(int argc, char **argv) {
  FILE *f = fopen(argv[1], "r");
  unsigned char c;
  while (1) {
    c = fgetc(f);
    if (feof(f)) {
      break;
    }
    printf("(byte)0x%02x, ", c);
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11a2 <main+0x52>
jmp    11b7 <main+0x67>
lea    0xe59(%rip),%rdi
movzbl -0x19(%rbp),%esi
call   1040 <printf@plt>
jmp    117e <main+0x2e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11b2 <main+0x62>
lea    0xe7c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl %bl,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"(byte)0x%02x, \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
br label %12
12: ; preds = %2, %19
%13 = load i32*, i32** %6
%14 = call zeroext i8 @fgetc(i32* %13)
store i8 %14, i8* %7
%15 = load i32*, i32** %6
%16 = call i64 @feof(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
br label %22
19: ; preds = %12
%20 = load i8, i8* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %20)
br label %12
22: ; preds = %18
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"(byte)0x%02x, \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call zeroext i8 @fgetc(i32* %5)
%7 = tail call i64 @feof(i32* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %2, %9
%10 = phi i8 [ %12, %9 ], [ %6, %2 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %10)
%12 = tail call zeroext i8 @fgetc(i32* %5)
%13 = tail call i64 @feof(i32* %5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %9, %2
%16 = tail call i32 @fclose(i32* %5)
ret i32 0
}