void fig08_07() {
  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);
}


x86 assembly (clang, -O0):
<fig08_07>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%r8
mov    -0x10(%rbp),%r11
mov    -0x18(%rbp),%rax
add    $0x237,%rax
lea    0xea9(%rip),%rdi
lea    0xebd(%rip),%rsi
lea    0xece(%rip),%rcx
lea    0xedf(%rip),%r9
lea    0xf01(%rip),%r10
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig08_07>:
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    $0x28,%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 void @fig08_07() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i64
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = load i8*, i8** %1
%5 = call i64 @strtol(i8* %4, i8** %2, i32 0)
store i64 %5, i64* %3
%6 = load i8*, i8** %1
%7 = load i64, i64* %3
%8 = load i8*, i8** %2
%9 = load i64, i64* %3
%10 = add nsw i64 %9, 567
%11 = 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* %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i64 %10)
ret void
}

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 void @fig08_07() {
%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 void
}