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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
lea    -0x30(%rbp),%rdi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x45(%rbp)
je     11a1 <main+0x51>
movsbl -0x30(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x45(%rbp)
mov    -0x45(%rbp),%al
test   $0x1,%al
jne    11b1 <main+0x61>
jmp    1231 <main+0xe1>
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x38(%rbp),%rax
lea    0xe32(%rip),%rdi
movsbl (%rax),%ecx
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x10,%edx
call   1070 <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   1050 <printf@plt>
jmp    116b <main+0x1b>
mov    -0x4(%rbp),%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    0xe9c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e78(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1222 <main+0xd2>
cmpb   $0xa,0x10(%rsp)
je     1222 <main+0xd2>
lea    0x8(%rsp),%r14
lea    0xe7f(%rip),%r15
lea    0xeb0(%rip),%r12
nopl   (%rax)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1070 <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   1070 <strtol@plt>
mov    0x8(%rsp),%rdx
movsbl (%rdx),%ecx
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     1222 <main+0xd2>
cmpb   $0xa,0x10(%rsp)
jne    11b0 <main+0x60>
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"
@stdin = global i32 0
@.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 10 input, base 16 output: %ld, stopped at %s (%d)\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %19, %0
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 30, i32 %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %7
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br label %17
17: ; preds = %12, %7
%18 = phi i1 [ false, %7 ], [ %16, %12 ]
br i1 %18, label %19, label %40
19: ; preds = %17
%20 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%27 = call i64 @strtol(i8* %26, i8** %3, i32 10)
store i64 %27, i64* %4
%28 = load i64, i64* %4
%29 = load i8*, i8** %3
%30 = load i8*, i8** %3
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %28, i8* %29, i8 signext %31)
%33 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%34 = call i64 @strtol(i8* %33, i8** %3, i32 16)
store i64 %34, i64* %4
%35 = load i64, i64* %4
%36 = load i8*, i8** %3
%37 = load i8*, i8** %3
%38 = load i8, i8* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %35, i8* %36, i8 signext %38)
br label %7
40: ; preds = %17
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@.str = [37 x i8] c"Enter a number (empty line to quit):\00"
@stdin = global i32 0
@.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 10 input, base 16 output: %ld, stopped at %s (%d)\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 = load i32, i32* @stdin
%7 = call i32* @fgets(i8* %3, i32 30, i32 %6)
%8 = icmp ne i32* %7, null
%9 = load i8, i8* %3
%10 = icmp ne i8 %9, 10
%11 = select i1 %8, i1 %10, i1 false
br i1 %11, label %12, label %31
12: ; preds = %0, %12
%13 = call i32 @strlen(i8* %3)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %15
store i8 0, i8* %16
%17 = call i64 @strtol(i8* %3, i8** %2, i32 10)
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i64 %17, i8* %18, i8 signext %19)
%21 = call i64 @strtol(i8* %3, i8** %2, i32 16)
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i64 %21, i8* %22, i8 signext %23)
%25 = load i32, i32* @stdin
%26 = call i32* @fgets(i8* %3, i32 30, i32 %25)
%27 = icmp ne i32* %26, null
%28 = load i8, i8* %3
%29 = icmp ne i8 %28, 10
%30 = select i1 %27, i1 %29, i1 false
br i1 %30, label %12, label %31
31: ; preds = %12, %0
ret i32 0
}