#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 hex2int(char *, size_t);
scalar_t__ readexactly(int, char *, size_t);
int /*<<< orphan*/ writexactly(int, char *, size_t);
long int readHex(int fd, char *buf, size_t len, char *cmd, size_t cmdlen) {
  int ret;
  if ((readexactly(fd, buf, len) < 0) || ((ret = hex2int(buf, len)) < 0)) {
    if (cmd != NULL)
      writexactly(fd, cmd, cmdlen);
    return -1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<readHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <readexactly@plt>
cmp    $0x0,%rax
jl     117e <readHex+0x4e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <hex2int@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11a6 <readHex+0x76>
cmpq   $0x0,-0x28(%rbp)
je     1199 <readHex+0x69>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <writexactly@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11ae <readHex+0x7e>
movslq -0x34(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readHex>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r12d
call   1050 <readexactly@plt>
test   %rax,%rax
js     1164 <readHex+0x34>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <hex2int@plt>
test   %eax,%eax
js     1164 <readHex+0x34>
mov    %eax,%ebx
jmp    117e <readHex+0x4e>
mov    $0xffffffffffffffff,%rbx
test   %r15,%r15
je     117e <readHex+0x4e>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <writexactly@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @readHex(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i64 %4, i64* %11
%13 = load i32, i32* %7
%14 = load i8*, i8** %8
%15 = load i64, i64* %9
%16 = call i64 @readexactly(i32 %13, i8* %14, i64 %15)
%17 = icmp slt i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %5
%19 = load i8*, i8** %8
%20 = load i64, i64* %9
%21 = call i32 @hex2int(i8* %19, i64 %20)
store i32 %21, i32* %12
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18, %5
%24 = load i8*, i8** %10
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %7
%28 = load i8*, i8** %10
%29 = load i64, i64* %11
%30 = call i32 @writexactly(i32 %27, i8* %28, i64 %29)
br label %31
31: ; preds = %26, %23
store i64 -1, i64* %6
br label %35
32: ; preds = %18
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
store i64 %34, i64* %6
br label %35
35: ; preds = %32, %31
%36 = load i64, i64* %6
ret i64 %36
}

LLVM IR (-O2):
define i64 @readHex(i32 %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = tail call i64 @readexactly(i32 %0, i8* %1, i64 %2)
%7 = icmp slt i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @hex2int(i8* %1, i64 %2)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8, %5
%12 = icmp eq i8* %3, null
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = tail call i32 @writexactly(i32 %0, i8* %3, i64 %4)
br label %17
15: ; preds = %8
%16 = zext i32 %9 to i64
br label %17
17: ; preds = %11, %13, %15
%18 = phi i64 [ %16, %15 ], [ -1, %13 ], [ -1, %11 ]
ret i64 %18
}