#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 */

/* Variables and functions */
int fread(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  unsigned char byte;
  printf("X'");
  while (1) {
    if (fread(&byte, 1, 1, stdin) != 1) {
      break;
    }
    printf("%02x", (unsigned int)byte);
  }
  printf("'\n");
  return 0;
}


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)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e9d(%rip),%rax
mov    (%rax),%ecx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x1,%eax
je     116b <main+0x4b>
jmp    1182 <main+0x62>
movzbl -0x11(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1144 <main+0x24>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e9a(%rip),%r15
mov    (%r15),%ecx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11a9 <main+0x79>
lea    0xe92(%rip),%r14
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0xf(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1180 <main+0x50>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"X'\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [3 x i8] c"'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %2, %13
%9 = load i32, i32* @stdin
%10 = call i32 @fread(i8* %6, i32 1, i32 1, i32 %9)
%11 = icmp ne i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %8
br label %17
13: ; preds = %8
%14 = load i8, i8* %6
%15 = zext i8 %14 to i32
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %8
17: ; preds = %12
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"X'\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"%02x\00"
@str = [2 x i8] c"'\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call i32 @fread(i8* %3, i32 1, i32 1, i32 %5)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %15
8: ; preds = %2, %8
%9 = load i8, i8* %3
%10 = zext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @stdin
%13 = call i32 @fread(i8* %3, i32 1, i32 1, i32 %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %8, label %15
15: ; preds = %8, %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret i32 0
}