#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*/ close_(int /*<<< orphan*/);
int /*<<< orphan*/ getsn(unsigned char *, int);
int open_(unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ puthex_b(char);
int /*<<< orphan*/ puts0(char *);
scalar_t__ readc(int /*<<< orphan*/, char *);
void hexcat(void) {
  unsigned short int i;
  unsigned short int j;
  unsigned short int equal;
  unsigned char filename[16 + 2];
  unsigned char str[256];
  char c;
  int rc;
  int line = 0;
  puts0("file ? ");
  for (i = 0; i < 16; i++)
    str[i] = 0;
  getsn(str, 256);
  for (i = 0; i < 16; i++)
    filename[i] = str[i];
  filename[16] = 0;
  rc = open_(filename, 0);
  if (rc != -1) {
  } else {
    puts0("can't open file\r\n");
    return;
  }
  while (readc(0, &c) == 0)
    puthex_b(c);
  close_(0);
}


x86 assembly (clang, -O0):
<hexcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x12c(%rbp)
lea    0xe84(%rip),%rdi
call   1060 <puts0@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x10,%eax
jge    11b1 <hexcat+0x51>
movzwl -0x2(%rbp),%eax
movb   $0x0,-0x120(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    1187 <hexcat+0x27>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1030 <getsn@plt>
movw   $0x0,-0x2(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x10,%eax
jge    11f9 <hexcat+0x99>
movzwl -0x2(%rbp),%eax
mov    -0x120(%rbp,%rax,1),%cl
movzwl -0x2(%rbp),%eax
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    11c8 <hexcat+0x68>
movb   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <open_@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0xffffffff,-0x128(%rbp)
je     1220 <hexcat+0xc0>
jmp    1231 <hexcat+0xd1>
lea    0xde1(%rip),%rdi
call   1060 <puts0@plt>
jmp    1266 <hexcat+0x106>
jmp    1236 <hexcat+0xd6>
xor    %edi,%edi
lea    -0x121(%rbp),%rsi
call   1070 <readc@plt>
cmp    $0x0,%rax
jne    125f <hexcat+0xff>
movsbl -0x121(%rbp),%edi
call   1040 <puthex_b@plt>
jmp    1236 <hexcat+0xd6>
xor    %edi,%edi
call   1080 <close_@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexcat>:
push   %rbx
sub    $0x130,%rsp
lea    0xe91(%rip),%rdi
call   1060 <puts0@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
mov    $0x100,%esi
call   1030 <getsn@plt>
movaps 0x30(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <open_@plt>
cmp    $0xffffffff,%eax
je     11f2 <hexcat+0x92>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
call   1070 <readc@plt>
test   %rax,%rax
jne    11e9 <hexcat+0x89>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl 0xf(%rsp),%edi
call   1040 <puthex_b@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <readc@plt>
test   %rax,%rax
je     11d0 <hexcat+0x70>
xor    %edi,%edi
call   1080 <close_@plt>
jmp    11fe <hexcat+0x9e>
lea    0xe0f(%rip),%rdi
call   1060 <puts0@plt>
add    $0x130,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"file ? \00"
@.str.1 = [18 x i8] c"can't open file\0D\0A\00"
define void @hexcat() {
%1 = alloca i16
%2 = alloca i16
%3 = alloca i16
%4 = alloca [18 x i8]
%5 = alloca [256 x i8]
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %8
%9 = call i32 @puts0(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i16 0, i16* %1
br label %10
10: ; preds = %18, %0
%11 = load i16, i16* %1
%12 = zext i16 %11 to i32
%13 = icmp slt i32 %12, 16
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = load i16, i16* %1
%16 = zext i16 %15 to i64
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14
%19 = load i16, i16* %1
%20 = add i16 %19, 1
store i16 %20, i16* %1
br label %10
21: ; preds = %10
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%23 = call i32 @getsn(i8* %22, i32 256)
store i16 0, i16* %1
br label %24
24: ; preds = %36, %21
%25 = load i16, i16* %1
%26 = zext i16 %25 to i32
%27 = icmp slt i32 %26, 16
br i1 %27, label %28, label %39
28: ; preds = %24
%29 = load i16, i16* %1
%30 = zext i16 %29 to i64
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i16, i16* %1
%34 = zext i16 %33 to i64
%35 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 %34
store i8 %32, i8* %35
br label %36
36: ; preds = %28
%37 = load i16, i16* %1
%38 = add i16 %37, 1
store i16 %38, i16* %1
br label %24
39: ; preds = %24
%40 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 16
store i8 0, i8* %40
%41 = getelementptr inbounds [18 x i8], [18 x i8]* %4, i64 0, i64 0
%42 = call i32 @open_(i8* %41, i32 0)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %39
br label %48
46: ; preds = %39
%47 = call i32 @puts0(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %57
48: ; preds = %45
br label %49
49: ; preds = %52, %48
%50 = call i64 @readc(i32 0, i8* %6)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = load i8, i8* %6
%54 = call i32 @puthex_b(i8 signext %53)
br label %49
55: ; preds = %49
%56 = call i32 @close_(i32 0)
br label %57
57: ; preds = %55, %46
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"file ? \00"
@.str.1 = [18 x i8] c"can't open file\0D\0A\00"
define void @hexcat() {
%1 = alloca [18 x i8]
%2 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = alloca i8
%6 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = tail call i32 @puts0(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @getsn(i8* %7, i32 256)
%10 = getelementptr inbounds [18 x i8], [18 x i8]* %1, i64 0, i64 16
store i8 0, i8* %10
%11 = call i32 @open_(i8* %6, i32 0)
%12 = icmp eq i32 %11, -1
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = call i64 @readc(i32 0, i8* %5)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %23
16: ; preds = %0
%17 = call i32 @puts0(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %25
18: ; preds = %13, %18
%19 = load i8, i8* %5
%20 = call i32 @puthex_b(i8 signext %19)
%21 = call i64 @readc(i32 0, i8* %5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %18, label %23
23: ; preds = %18, %13
%24 = call i32 @close_(i32 0)
br label %25
25: ; preds = %23, %16
ret void
}