#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*/ printf(char *, ...);
double strtod(char *, char **);
int main() {
  char *str = "20.3012308 hello world! 32";
  char *ptr;
  double val;
  do {
    val = strtod(str, &ptr);
    printf("val: %lf\n", val);
    printf("string: %s\n", ptr);
    str = ptr;
  } while (val != 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xec3(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    113a <main+0x1a>
jp     113a <main+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xed6(%rip),%rbx
lea    0x10(%rsp),%r14
lea    0xee5(%rip),%r15
lea    0xee8(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strtod@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x10(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0x8(%rsp),%xmm0
ucomisd 0xe75(%rip),%xmm0
jne    1150 <main+0x30>
jp     1150 <main+0x30>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [27 x i8] c"20.3012308 hello world! 32\00"
@.str.1 = [10 x i8] c"val: %lf\0A\00"
@.str.2 = [12 x i8] c"string: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
store i32 0, i32* %1
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8** %2
br label %5
5: ; preds = %13, %0
%6 = load i8*, i8** %2
%7 = call double @strtod(i8* %6, i8** %3)
store double %7, double* %4
%8 = load double, double* %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %8)
%10 = load i8*, i8** %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
store i8* %12, i8** %2
br label %13
13: ; preds = %5
%14 = load double, double* %4
%15 = fcmp une double %14, 0.000000e+00
br i1 %15, label %5, label %16
16: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"20.3012308 hello world! 32\00"
@.str.1 = [10 x i8] c"val: %lf\0A\00"
@.str.2 = [12 x i8] c"string: %s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %0 ], [ %7, %3 ]
%5 = call double @strtod(i8* %4, i8** %1)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double %5)
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%9 = fcmp une double %5, 0.000000e+00
br i1 %9, label %3, label %10
10: ; preds = %3
ret i32 0
}