#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 int /*<<< orphan*/ lbuf;

/* Variables and functions */
int read(int /*<<< orphan*/, ...);
intptr_t strtol(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ x_perror(char *);
intptr_t read_long(void) {
  unsigned char size;
  char lbuf[64];
  if (read(0, &size, 1) != 1 || size > sizeof(lbuf) - 1) {
    x_perror("read_long");
  }
  if (read(0, lbuf, size) != (int)size) {
    x_perror("read_long");
  }
  lbuf[size] = 0;
  return strtol(lbuf, 0, 16);
}


x86 assembly (clang, -O0):
<read_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
xor    %edi,%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1161 <read_long+0x31>
movzbl -0x1(%rbp),%eax
cmp    $0x3f,%rax
jbe    116d <read_long+0x3d>
lea    0xe98(%rip),%rdi
call   1030 <x_perror@plt>
lea    -0x50(%rbp),%rsi
movzbl -0x1(%rbp),%edx
xor    %edi,%edi
mov    $0x0,%al
call   1040 <read@plt>
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
je     1196 <read_long+0x66>
lea    0xe6f(%rip),%rdi
call   1030 <x_perror@plt>
movzbl -0x1(%rbp),%eax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_long>:
sub    $0x58,%rsp
lea    0xf(%rsp),%rsi
xor    %edi,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <read@plt>
cmp    $0x1,%eax
jne    1154 <read_long+0x24>
mov    0xf(%rsp),%al
cmp    $0x40,%al
jb     1164 <read_long+0x34>
lea    0xea5(%rip),%rdi
call   1030 <x_perror@plt>
mov    0xf(%rsp),%al
movzbl %al,%edx
lea    0x10(%rsp),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1040 <read@plt>
movzbl 0xf(%rsp),%ecx
cmp    %ecx,%eax
je     118e <read_long+0x5e>
lea    0xe7b(%rip),%rdi
call   1030 <x_perror@plt>
mov    0xf(%rsp),%cl
movzbl %cl,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
add    $0x58,%rsp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"read_long\00"
define i64 @read_long() {
%1 = alloca i8
%2 = alloca [64 x i8]
%3 = call i32 (i32, ...) @read(i32 0, i8* %1, i32 1)
%4 = icmp ne i32 %3, 1
br i1 %4, label %9, label %5
5: ; preds = %0
%6 = load i8, i8* %1
%7 = zext i8 %6 to i64
%8 = icmp ugt i64 %7, 63
br i1 %8, label %9, label %11
9: ; preds = %5, %0
%10 = call i32 @x_perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %1
%14 = zext i8 %13 to i32
%15 = call i32 (i32, ...) @read(i32 0, i8* %12, i32 %14)
%16 = load i8, i8* %1
%17 = zext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @x_perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %11
%22 = load i8, i8* %1
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %23
store i8 0, i8* %24
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%26 = call i64 @strtol(i8* %25, i32 0, i32 16)
ret i64 %26
}

LLVM IR (-O2):
@.str = [10 x i8] c"read_long\00"
define i64 @read_long() {
%1 = alloca i8
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 (i32, ...) @read(i32 0, i8* %1, i32 1)
%5 = icmp ne i32 %4, 1
%6 = load i8, i8* %1
%7 = icmp ugt i8 %6, 63
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @x_perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = load i8, i8* %1
br label %12
12: ; preds = %0, %9
%13 = phi i8 [ %6, %0 ], [ %11, %9 ]
%14 = zext i8 %13 to i32
%15 = call i32 (i32, ...) @read(i32 0, i8* %3, i32 %14)
%16 = load i8, i8* %1
%17 = zext i8 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = call i32 @x_perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%21 = load i8, i8* %1
br label %22
22: ; preds = %19, %12
%23 = phi i8 [ %21, %19 ], [ %16, %12 ]
%24 = zext i8 %23 to i64
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i64 @strtol(i8* %3, i32 0, i32 16)
ret i64 %26
}