#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*/ errno;
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
char *strtol(char *, char **, int);
int main(void) {
  char *end;
  printf("\" 999999999999999999999999999999999999999999999\" em decimal --> "
         "%ld - ",
         strtol(" 999999999999999999999999999999999999999999999", &end, 10));
  printf("Erro: %s\n", strerror(errno));
  printf("\"1010\" em binário --> %ld\n", strtol("1010", NULL, 2));
  printf("\"12\" em octal     --> %ld\n", strtol("12", NULL, 8));
  printf("\"A\"  em hex       --> %ld\n", strtol("A", NULL, 16));
  printf("\"junk\" em base 36 --> %ld\n", strtol("junk", NULL, 36));
  printf("\"012\" detecção    --> %ld\n", strtol("012", NULL, 0));
  printf("\"0xA\" detecção    --> %ld\n", strtol("0xA", NULL, 0));
  printf("\"junk\" detecção   -->  %ld - ", strtol("junk", &end, 0));
  printf("Erro: %s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xf08(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xf02(%rip),%rdi
call   1030 <printf@plt>
lea    0xf1c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xee8(%rip),%rdi
call   1030 <printf@plt>
lea    0xf71(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x8,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xee5(%rip),%rdi
call   1030 <printf@plt>
lea    0xf6f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
lea    0xf06(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x24,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
lea    0xf04(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rsi
lea    0xed2(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xdf2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xf07(%rip),%rdi
lea    0x8(%rsp),%r14
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
lea    0xea7(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    0x2e78(%rip),%r15
mov    (%r15),%edi
call   1050 <strerror@plt>
lea    0xeff(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xef7(%rip),%rdi
call   1030 <printf@plt>
lea    0xf07(%rip),%rdi
call   1030 <printf@plt>
lea    0xf16(%rip),%rdi
call   1030 <printf@plt>
lea    0xf25(%rip),%rdi
call   1030 <printf@plt>
lea    0xf39(%rip),%rdi
call   1030 <printf@plt>
lea    0xf4a(%rip),%rdi
call   1030 <printf@plt>
lea    0xf1c(%rip),%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
lea    0xf4a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    (%r15),%edi
call   1050 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [71 x i8] c"\22 999999999999999999999999999999999999999999999\22 em decimal --> %ld - \00"
@.str.1 = [47 x i8] c" 999999999999999999999999999999999999999999999\00"
@.str.2 = [10 x i8] c"Erro: %s\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"\221010\22 em bin\C3\A1rio --> %ld\0A\00"
@.str.4 = [5 x i8] c"1010\00"
@.str.5 = [27 x i8] c"\2212\22 em octal --> %ld\0A\00"
@.str.6 = [3 x i8] c"12\00"
@.str.7 = [27 x i8] c"\22A\22 em hex --> %ld\0A\00"
@.str.8 = [2 x i8] c"A\00"
@.str.9 = [27 x i8] c"\22junk\22 em base 36 --> %ld\0A\00"
@.str.10 = [5 x i8] c"junk\00"
@.str.11 = [29 x i8] c"\22012\22 detec\C3\A7\C3\A3o --> %ld\0A\00"
@.str.12 = [4 x i8] c"012\00"
@.str.13 = [29 x i8] c"\220xA\22 detec\C3\A7\C3\A3o --> %ld\0A\00"
@.str.14 = [4 x i8] c"0xA\00"
@.str.15 = [32 x i8] c"\22junk\22 detec\C3\A7\C3\A3o --> %ld - \00"
define i32 @main() {
%1 = alloca i8*
%2 = call i8* @strtol(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8** %1, i32 10)
%3 = call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i32, i32* @errno
%5 = call i8* @strerror(i32 %4)
%6 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = call i8* @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** null, i32 2)
%8 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%9 = call i8* @strtol(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** null, i32 8)
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %9)
%11 = call i8* @strtol(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8** null, i32 16)
%12 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i8* %11)
%13 = call i8* @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** null, i32 36)
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i8* %13)
%15 = call i8* @strtol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i8** null, i32 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i8* %15)
%17 = call i8* @strtol(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.14, i64 0, i64 0), i8** null, i32 0)
%18 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i8* %17)
%19 = call i8* @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** %1, i32 0)
%20 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [71 x i8] c"\22 999999999999999999999999999999999999999999999\22 em decimal --> %ld - \00"
@.str.1 = [47 x i8] c" 999999999999999999999999999999999999999999999\00"
@.str.2 = [10 x i8] c"Erro: %s\0A\00"
@errno = global i32 0
@.str.3 = [28 x i8] c"\221010\22 em bin\C3\A1rio --> %ld\0A\00"
@.str.5 = [27 x i8] c"\2212\22 em octal --> %ld\0A\00"
@.str.7 = [27 x i8] c"\22A\22 em hex --> %ld\0A\00"
@.str.9 = [27 x i8] c"\22junk\22 em base 36 --> %ld\0A\00"
@.str.10 = [5 x i8] c"junk\00"
@.str.11 = [29 x i8] c"\22012\22 detec\C3\A7\C3\A3o --> %ld\0A\00"
@.str.13 = [29 x i8] c"\220xA\22 detec\C3\A7\C3\A3o --> %ld\0A\00"
@.str.15 = [32 x i8] c"\22junk\22 detec\C3\A7\C3\A3o --> %ld - \00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call i8* @strtol(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8** %1, i32 10)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = load i32, i32* @errno
%6 = tail call i8* @strerror(i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i0 0)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i0 0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0), i0 0)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i0 0)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i0 0)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0), i0 0)
%14 = call i8* @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i8** %1, i32 0)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %17)
ret i32 0
}