#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 scalar_t__ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ raw2hex(char *, unsigned char *, scalar_t__);
scalar_t__ read(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ ulz_printf(char *, ...);
int usage(char *);
int main(int argc, char **argv) {
  unsigned char buf[1024];
  char out[2048 + 1];
  if (argc > 1)
    return usage(argv[0]);
  while (1) {
    ssize_t n = read(0, buf, sizeof buf);
    if (n <= 0)
      break;
    raw2hex(out, buf, n);
    ulz_printf("%s", out);
  }
  ulz_printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1177 <main+0x37>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <main+0xb2>
jmp    117c <main+0x3c>
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %rax,-0xc28(%rbp)
cmpq   $0x0,-0xc28(%rbp)
jg     11a9 <main+0x69>
jmp    11dd <main+0x9d>
lea    -0xc20(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0xc28(%rbp),%rdx
call   1030 <raw2hex@plt>
lea    -0xc20(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1040 <ulz_printf@plt>
jmp    117c <main+0x3c>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <ulz_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xc10,%rsp
cmp    $0x1,%edi
jle    1165 <main+0x25>
mov    (%rsi),%rdi
add    $0xc10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <usage@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    11bf <main+0x7f>
lea    0x400(%rsp),%r14
mov    %rsp,%rbx
lea    0xe75(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <raw2hex@plt>
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <ulz_printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1190 <main+0x50>
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1040 <ulz_printf@plt>
xor    %eax,%eax
add    $0xc10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [2049 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
store i32 %15, i32* %3
br label %32
16: ; preds = %2
br label %17
17: ; preds = %16, %23
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i64 @read(i32 0, i8* %18, i32 1024)
store i64 %19, i64* %8
%20 = load i64, i64* %8
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17
br label %30
23: ; preds = %17
%24 = getelementptr inbounds [2049 x i8], [2049 x i8]* %7, i64 0, i64 0
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i64, i64* %8
%27 = call i32 @raw2hex(i8* %24, i8* %25, i64 %26)
%28 = getelementptr inbounds [2049 x i8], [2049 x i8]* %7, i64 0, i64 0
%29 = call i32 (i8*, ...) @ulz_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %28)
br label %17
30: ; preds = %22
%31 = call i32 (i8*, ...) @ulz_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %32
32: ; preds = %30, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [2049 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [2049 x i8], [2049 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i64 @read(i32 0, i8* %5, i32 1024)
%10 = icmp slt i64 %9, 1
br i1 %10, label %20, label %14
11: ; preds = %2
%12 = load i8*, i8** %1
%13 = tail call i32 @usage(i8* %12)
br label %22
14: ; preds = %8, %14
%15 = phi i64 [ %18, %14 ], [ %9, %8 ]
%16 = call i32 @raw2hex(i8* %6, i8* %5, i64 %15)
%17 = call i32 (i8*, ...) @ulz_printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%18 = call i64 @read(i32 0, i8* %5, i32 1024)
%19 = icmp slt i64 %18, 1
br i1 %19, label %20, label %14
20: ; preds = %14, %8
%21 = call i32 (i8*, ...) @ulz_printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
%23 = phi i32 [ %13, %11 ], [ 0, %20 ]
ret i32 %23
}