#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 */
scalar_t__ gets(char *);
int /*<<< orphan*/ printf(char *, long, char *, char);
int /*<<< orphan*/ puts(char *);
long strtol(char *, char **, int);
int main() {
  char number[30];
  char *end;
  long value;
  puts("Enter a number (empty line to quit): ");
  while (gets(number) && number[0] != '\0') {
    value = strtol(number, &end, 10);
    printf("value: %ld, stopped at %s (%d) \n", value, end, *end);
    value = strtol(number, &end, 16);
    printf("value: %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
call   1060 <gets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x41(%rbp)
je     1183 <main+0x43>
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1193 <main+0x53>
jmp    1206 <main+0xc6>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
lea    0xe6a(%rip),%rdi
movsbl (%rax),%ecx
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
lea    0xe39(%rip),%rdi
movsbl (%rax),%ecx
call   1040 <printf@plt>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
jmp    115b <main+0x1b>
lea    0xe48(%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   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     11f2 <main+0xb2>
cmpb   $0x0,0x10(%rsp)
je     11f2 <main+0xb2>
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0xea0(%rip),%r15
lea    0xeba(%rip),%r12
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%ecx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     11f2 <main+0xb2>
cmpb   $0x0,0x10(%rsp)
jne    1190 <main+0x50>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Enter a number (empty line to quit): \00"
@.str.1 = [33 x i8] c"value: %ld, stopped at %s (%d) \0A\00"
@.str.2 = [14 x i8] c"Next number: \00"
@.str.3 = [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 ([38 x i8], [38 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 @gets(i8* %7)
%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 ([33 x i8], [33 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 ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %27, i8* %28, i8 signext %30)
%32 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %6
33: ; preds = %15
%34 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [38 x i8] c"Enter a number (empty line to quit): \00"
@.str.1 = [33 x i8] c"value: %ld, stopped at %s (%d) \0A\00"
@.str.2 = [14 x i8] c"Next number: \00"
@.str.3 = [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 ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%6 = call i64 @gets(i8* %3)
%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 ([33 x i8], [33 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 ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i64 %16, i8* %17, i8 signext %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%21 = call i64 @gets(i8* %3)
%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.3, i64 0, i64 0))
ret i32 0
}