#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 /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ stdout;
int stdin_bin_to_hex_pairs() {
  unsigned char c;
  while (read(0, &c, 1) > 0) {
    printf("%02x", c);
    fflush(stdout);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<stdin_bin_to_hex_pairs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    1177 <stdin_bin_to_hex_pairs+0x47>
movzbl -0x1(%rbp),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1138 <stdin_bin_to_hex_pairs+0x8>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdin_bin_to_hex_pairs>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11ab <stdin_bin_to_hex_pairs+0x6b>
lea    0xe9a(%rip),%r14
mov    0x2e73(%rip),%r15
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl 0xf(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edi
call   1060 <fflush@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1180 <stdin_bin_to_hex_pairs+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @stdin_bin_to_hex_pairs() {
%1 = alloca i8
br label %2
2: ; preds = %5, %0
%3 = call i64 @read(i32 0, i8* %1, i32 1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = load i8, i8* %1
%7 = zext i8 %6 to i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
br label %2
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@stdout = global i32 0
define i32 @stdin_bin_to_hex_pairs() {
%1 = alloca i8
%2 = call i64 @read(i32 0, i8* %1, i32 1)
%3 = icmp sgt i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %0, %4
%5 = load i8, i8* %1
%6 = zext i8 %5 to i32
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @stdout
%9 = tail call i32 @fflush(i32 %8)
%10 = call i64 @read(i32 0, i8* %1, i32 1)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %4, %0
%13 = tail call i32 @putchar(i32 10)
ret i32 0
}