#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 atodec(char *);
int atohex(char *);
int /*<<< orphan*/ read_string(char *, int);
int /*<<< orphan*/ sys_write(char *, int);
int input_number(int *value, char *ptr, int offset, int _num, int sel) {
  char buffer[16], *inptr;
  int off;
  off = offset;
  if (ptr == (char *)-1) {
    read_string(buffer, 15);
    sys_write("\n", 1);
    inptr = buffer;
  } else if (ptr > (char *)255) {
    while (ptr[off] <= ' ')
      off++;
    inptr = &(ptr[off]);
    while (ptr[off] > ' ')
      off++;
  }
  if (sel == 0)
    *value = atodec(inptr);
  else
    *value = atohex(inptr);
  return off;
}


x86 assembly (clang, -O0):
<input_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rax,-0x10(%rbp)
jne    119d <input_number+0x5d>
lea    -0x30(%rbp),%rdi
mov    $0xf,%esi
call   1060 <read_string@plt>
lea    0xe7a(%rip),%rdi
mov    $0x1,%esi
call   1050 <sys_write@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1210 <input_number+0xd0>
mov    $0xff,%eax
cmp    %rax,-0x10(%rbp)
jbe    120b <input_number+0xcb>
jmp    11b1 <input_number+0x71>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jg     11d4 <input_number+0x94>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b1 <input_number+0x71>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jle    1206 <input_number+0xc6>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e3 <input_number+0xa3>
jmp    120b <input_number+0xcb>
jmp    1210 <input_number+0xd0>
cmpl   $0x0,-0x1c(%rbp)
jne    1230 <input_number+0xf0>
mov    -0x38(%rbp),%rdi
call   1040 <atodec@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1241 <input_number+0x101>
mov    -0x38(%rbp),%rdi
call   1030 <atohex@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r15d
mov    %edx,%ebx
mov    %rdi,%r14
cmp    $0xffffffffffffffff,%rsi
je     119e <input_number+0x5e>
cmp    $0x100,%rsi
jb     11c1 <input_number+0x81>
movslq %ebx,%rax
lea    -0x2(%rax),%ebx
lea    (%rax,%rsi,1),%rbp
add    $0xffffffffffffffff,%rbp
nop
add    $0x1,%ebx
cmpb   $0x21,0x1(%rbp)
lea    0x1(%rbp),%rbp
jl     1170 <input_number+0x30>
lea    0x1(%rbx),%eax
cltq
add    %rax,%rsi
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cmpb   $0x20,(%rsi)
lea    0x1(%rsi),%rsi
jg     1190 <input_number+0x50>
jmp    11c1 <input_number+0x81>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0xf,%esi
call   1060 <read_string@plt>
lea    0xe4b(%rip),%rdi
mov    $0x1,%esi
call   1050 <sys_write@plt>
jmp    11c1 <input_number+0x81>
mov    %rbp,%rdi
test   %r15d,%r15d
je     11d0 <input_number+0x90>
call   1030 <atohex@plt>
jmp    11d5 <input_number+0x95>
call   1040 <atodec@plt>
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @input_number(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [16 x i8]
%12 = alloca i8*
%13 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%14 = load i32, i32* %8
store i32 %14, i32* %13
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, inttoptr (i64 -1 to i8*)
br i1 %16, label %17, label %22
17: ; preds = %5
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%19 = call i32 @read_string(i8* %18, i32 15)
%20 = call i32 @sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
store i8* %21, i8** %12
br label %55
22: ; preds = %5
%23 = load i8*, i8** %7
%24 = icmp ugt i8* %23, inttoptr (i64 255 to i8*)
br i1 %24, label %25, label %54
25: ; preds = %22
br label %26
26: ; preds = %34, %25
%27 = load i8*, i8** %7
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp sle i32 %32, 32
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = load i32, i32* %13
%36 = add nsw i32 %35, 1
store i32 %36, i32* %13
br label %26
37: ; preds = %26
%38 = load i8*, i8** %7
%39 = load i32, i32* %13
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8* %41, i8** %12
br label %42
42: ; preds = %50, %37
%43 = load i8*, i8** %7
%44 = load i32, i32* %13
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp sgt i32 %48, 32
br i1 %49, label %50, label %53
50: ; preds = %42
%51 = load i32, i32* %13
%52 = add nsw i32 %51, 1
store i32 %52, i32* %13
br label %42
53: ; preds = %42
br label %54
54: ; preds = %53, %22
br label %55
55: ; preds = %54, %17
%56 = load i32, i32* %10
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %55
%59 = load i8*, i8** %12
%60 = call i32 @atodec(i8* %59)
%61 = load i32*, i32** %6
store i32 %60, i32* %61
br label %66
62: ; preds = %55
%63 = load i8*, i8** %12
%64 = call i32 @atohex(i8* %63)
%65 = load i32*, i32** %6
store i32 %64, i32* %65
br label %66
66: ; preds = %62, %58
%67 = load i32, i32* %13
ret i32 %67
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @input_number(i32* nocapture writeonly %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%8 = icmp eq i8* %1, inttoptr (i64 -1 to i8*)
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = call i32 @read_string(i8* %7, i32 15)
%11 = call i32 @sys_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %34
12: ; preds = %5
%13 = icmp ugt i8* %1, inttoptr (i64 255 to i8*)
br i1 %13, label %14, label %34
14: ; preds = %12
%15 = sext i32 %2 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %15, %14 ], [ %21, %16 ]
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = icmp slt i8 %19, 33
%21 = add i64 %17, 1
br i1 %20, label %16, label %22
22: ; preds = %16
%23 = getelementptr inbounds i8, i8* %1, i64 %17
%24 = shl i64 %17, 32
%25 = ashr exact i64 %24, 32
br label %26
26: ; preds = %26, %22
%27 = phi i64 [ %31, %26 ], [ %25, %22 ]
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = icmp sgt i8 %29, 32
%31 = add i64 %27, 1
br i1 %30, label %26, label %32
32: ; preds = %26
%33 = trunc i64 %27 to i32
br label %34
34: ; preds = %32, %12, %9
%35 = phi i8* [ %7, %9 ], [ undef, %12 ], [ %23, %32 ]
%36 = phi i32 [ %2, %9 ], [ %2, %12 ], [ %33, %32 ]
%37 = icmp eq i32 %4, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @atodec(i8* %35)
br label %42
40: ; preds = %34
%41 = call i32 @atohex(i8* %35)
br label %42
42: ; preds = %40, %38
%43 = phi i32 [ %41, %40 ], [ %39, %38 ]
store i32 %43, i32* %0
ret i32 %36
}