int main(void) {
  const char *string = "-1234567abc";
  char *remainderPtr;
  long x;
  x = strtol(string, &remainderPtr, 0);
  printf("%s\"%s\"\n%s%ld\n%s\"%s\"\n%s%ld\n", "The original string is ",
         string, "The converted value is ", x,
         "The remainder of the original string is ", remainderPtr,
         "The converted value plus 567 is ", x + 567);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%r8
mov    -0x18(%rbp),%r11
mov    -0x20(%rbp),%rax
add    $0x237,%rax
lea    0xea2(%rip),%rdi
lea    0xeb6(%rip),%rsi
lea    0xec7(%rip),%rcx
lea    0xed8(%rip),%r9
lea    0xefa(%rip),%r10
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
lea    0x237(%rax),%rbx
sub    $0x8,%rsp
lea    0xf36(%rip),%r10
lea    0xebb(%rip),%rdi
lea    0xecf(%rip),%rsi
lea    0xee0(%rip),%rcx
lea    0xef1(%rip),%r9
mov    %r14,%rdx
mov    %rax,%r8
xor    %eax,%eax
push   %rbx
push   %r10
push   0x18(%rsp)
call   1030 <printf@plt>
add    $0x20,%rsp
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"-1234567abc\00"
@.str.1 = [27 x i8] c"%s\22%s\22\0A%s%ld\0A%s\22%s\22\0A%s%ld\0A\00"
@.str.2 = [24 x i8] c"The original string is \00"
@.str.3 = [24 x i8] c"The converted value is \00"
@.str.4 = [41 x i8] c"The remainder of the original string is \00"
@.str.5 = [33 x i8] c"The converted value plus 567 is \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %3, i32 0)
store i64 %6, i64* %4
%7 = load i8*, i8** %2
%8 = load i64, i64* %4
%9 = load i8*, i8** %3
%10 = load i64, i64* %4
%11 = add nsw i64 %10, 567
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %8, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %11)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"-1234567abc\00"
@.str.1 = [27 x i8] c"%s\22%s\22\0A%s%ld\0A%s\22%s\22\0A%s%ld\0A\00"
@.str.2 = [24 x i8] c"The original string is \00"
@.str.3 = [24 x i8] c"The converted value is \00"
@.str.4 = [41 x i8] c"The remainder of the original string is \00"
@.str.5 = [33 x i8] c"The converted value plus 567 is \00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call i64 @strtol(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %1, i32 0)
%4 = load i8*, i8** %1
%5 = add nsw i64 %3, 567
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %3, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %5)
ret i32 0
}