#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 */
scalar_t__ atof(char *);
char *ext_arg(char *, char *);
scalar_t__ strcmp(char *, char *);
double cal_add(char *S) {
  char *tmp = S;
  char arg[50];
  double sum = 0;
  for (; strcmp(tmp, "") != 0;) {
    tmp = ext_arg(tmp, arg);
    sum += atof(arg);
  }
  return sum;
}


x86 assembly (clang, -O0):
<cal_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1194 <cal_add+0x64>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <ext_arg@plt>
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
call   1030 <atof@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    114c <cal_add+0x1c>
movsd  -0x58(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal_add>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rdi,%rbx
lea    0xebd(%rip),%rsi
call   1050 <strcmp@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
je     11b0 <cal_add+0x80>
movsd  %xmm0,0x8(%rsp)
lea    0x10(%rsp),%r14
lea    0xe9d(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <ext_arg@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <atof@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    1170 <cal_add+0x40>
jmp    11b6 <cal_add+0x86>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define double @cal_add(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [50 x i8]
%5 = alloca double
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store double 0.000000e+00, double* %5
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %3
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%14 = call i8* @ext_arg(i8* %12, i8* %13)
store i8* %14, i8** %3
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%16 = call i64 @atof(i8* %15)
%17 = sitofp i64 %16 to double
%18 = load double, double* %5
%19 = fadd double %18, %17
store double %19, double* %5
br label %7
20: ; preds = %7
%21 = load double, double* %5
ret double %21
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define double @cal_add(i8* %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %1, %6
%7 = phi double [ %12, %6 ], [ 0.000000e+00, %1 ]
%8 = phi i8* [ %9, %6 ], [ %0, %1 ]
%9 = call i8* @ext_arg(i8* %8, i8* %3)
%10 = call i64 @atof(i8* %3)
%11 = sitofp i64 %10 to double
%12 = fadd double %7, %11
%13 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6, %1
%16 = phi double [ 0.000000e+00, %1 ], [ %12, %6 ]
ret double %16
}