#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*/ printf(char *, long, char *, char);
int /*<<< orphan*/ puts(char *);
scalar_t__ s_gets(char *, int);
long strtol(char *, char **, int);
int main(void) {
  char number[30];
  char *end;
  long value;
  puts("Enter a number (empty line to quit):");
  while (s_gets(number, 30) && number[0] != '\0') {
    value = strtol(number, &end, 10);
    printf("Base 10 input, base 10 output: %ld, stopped at %s (%d)\n", value,
           end, *end);
    value = strtol(number, &end, 16);
    printf("base 16 input, base 10 output: %ld, stopped at %s (%d)\n", value,
           end, *end);
    puts("Next number:");
  }
  puts("Bye!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    $0x1e,%esi
call   1040 <s_gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x41(%rbp)
je     1188 <main+0x48>
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1198 <main+0x58>
jmp    120b <main+0xcb>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
lea    0xe64(%rip),%rdi
movsbl (%rax),%ecx
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
lea    0xe6b(%rip),%rdi
movsbl (%rax),%ecx
call   1050 <printf@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
jmp    115b <main+0x1b>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
mov    $0x1e,%esi
call   1040 <s_gets@plt>
test   %rax,%rax
je     1207 <main+0xc7>
cmpb   $0x0,0x10(%rsp)
je     1207 <main+0xc7>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xe98(%rip),%r15
lea    0xec9(%rip),%r12
lea    0xefa(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%ecx
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r13,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1040 <s_gets@plt>
test   %rax,%rax
je     1207 <main+0xc7>
cmpb   $0x0,0x10(%rsp)
jne    11a0 <main+0x60>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Enter a number (empty line to quit):\00"
@.str.1 = [56 x i8] c"Base 10 input, base 10 output: %ld, stopped at %s (%d)\0A\00"
@.str.2 = [56 x i8] c"base 16 input, base 10 output: %ld, stopped at %s (%d)\0A\00"
@.str.3 = [13 x i8] c"Next number:\00"
@.str.4 = [6 x i8] c"Bye!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i8*
%4 = alloca i64
store i32 0, i32* %1
%5 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %17, %0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i64 @s_gets(i8* %7, i32 30)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br label %15
15: ; preds = %10, %6
%16 = phi i1 [ false, %6 ], [ %14, %10 ]
br i1 %16, label %17, label %33
17: ; preds = %15
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%19 = call i64 @strtol(i8* %18, i8** %3, i32 10)
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = load i8*, i8** %3
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %20, i8* %21, i8 signext %23)
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%26 = call i64 @strtol(i8* %25, i8** %3, i32 16)
store i64 %26, i64* %4
%27 = load i64, i64* %4
%28 = load i8*, i8** %3
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %27, i8* %28, i8 signext %30)
%32 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %6
33: ; preds = %15
%34 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter a number (empty line to quit):\00"
@.str.1 = [56 x i8] c"Base 10 input, base 10 output: %ld, stopped at %s (%d)\0A\00"
@.str.2 = [56 x i8] c"base 16 input, base 10 output: %ld, stopped at %s (%d)\0A\00"
@.str.3 = [13 x i8] c"Next number:\00"
@.str.4 = [6 x i8] c"Bye!\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @s_gets(i8* %3, i32 30)
%7 = icmp ne i64 %6, 0
%8 = load i8, i8* %3
%9 = icmp ne i8 %8, 0
%10 = select i1 %7, i1 %9, i1 false
br i1 %10, label %11, label %26
11: ; preds = %0, %11
%12 = call i64 @strtol(i8* %3, i8** %2, i32 10)
%13 = load i8*, i8** %2
%14 = load i8, i8* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %12, i8* %13, i8 signext %14)
%16 = call i64 @strtol(i8* %3, i8** %2, i32 16)
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %16, i8* %17, i8 signext %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%21 = call i64 @s_gets(i8* %3, i32 30)
%22 = icmp ne i64 %21, 0
%23 = load i8, i8* %3
%24 = icmp ne i8 %23, 0
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %11, label %26
26: ; preds = %11, %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}