#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__ isdigit(char const);
scalar_t__ ms2deg(int, float);
double dms2d(const char *d, int m, float s) {
  double sign;
  double ret;
  if (*d == '-') {
    sign = -1;
    d++;
  } else {
    sign = 1;
    if (*d == '+')
      d++;
  }
  ret = 0;
  while (isdigit(*d)) {
    ret *= 10.0;
    ret += *d++ - '0';
  }
  ret += ms2deg(m, s);
  return ret * sign;
}


x86 assembly (clang, -O0):
<dms2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movss  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1162 <dms2d+0x42>
movsd  0xebc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <dms2d+0x70>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    118b <dms2d+0x6b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1190 <dms2d+0x70>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e8 <dms2d+0xc8>
movsd  0xe5a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1198 <dms2d+0x78>
mov    -0xc(%rbp),%edi
movss  -0x10(%rbp),%xmm0
call   1040 <ms2deg@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dms2d>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movss  %xmm0,0x14(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%al
movsd  0xec5(%rip),%xmm0
cmp    $0x2b,%al
je     1157 <dms2d+0x37>
cmp    $0x2d,%al
jne    114f <dms2d+0x2f>
add    $0x1,%rbx
movsd  0xeb9(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1161 <dms2d+0x41>
movsd  %xmm0,0x8(%rsp)
add    $0x1,%rbx
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11b7 <dms2d+0x97>
add    $0x1,%rbx
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  (%rsp),%xmm1
mulsd  0xe83(%rip),%xmm1
movsbl -0x1(%rbx),%eax
add    $0xffffffd0,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsbl (%rbx),%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1180 <dms2d+0x60>
jmp    11c0 <dms2d+0xa0>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
movss  0x14(%rsp),%xmm0
call   1040 <ms2deg@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define double @dms2d(i8* %0, i32 %1, float %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca float
%7 = alloca double
%8 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store float %2, float* %6
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 45
br i1 %12, label %13, label %16
13: ; preds = %3
store double -1.000000e+00, double* %7
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %25
16: ; preds = %3
store double 1.000000e+00, double* %7
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 43
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
br label %24
24: ; preds = %21, %16
br label %25
25: ; preds = %24, %13
store double 0.000000e+00, double* %8
br label %26
26: ; preds = %31, %25
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = call i64 @isdigit(i8 signext %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %42
31: ; preds = %26
%32 = load double, double* %8
%33 = fmul double %32, 1.000000e+01
store double %33, double* %8
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
%36 = load i8, i8* %34
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 48
%39 = sitofp i32 %38 to double
%40 = load double, double* %8
%41 = fadd double %40, %39
store double %41, double* %8
br label %26
42: ; preds = %26
%43 = load i32, i32* %5
%44 = load float, float* %6
%45 = call i64 @ms2deg(i32 %43, float %44)
%46 = sitofp i64 %45 to double
%47 = load double, double* %8
%48 = fadd double %47, %46
store double %48, double* %8
%49 = load double, double* %8
%50 = load double, double* %7
%51 = fmul double %49, %50
ret double %51
}

LLVM IR (-O2):
define double @dms2d(i8* nocapture %0, i32 %1, float %2) {
%4 = load i8, i8* %0
switch i8 %4, label %9 [
i8 45, label %5
i8 43, label %7
]
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 1
br label %9
7: ; preds = %3
%8 = getelementptr inbounds i8, i8* %0, i64 1
br label %9
9: ; preds = %3, %7, %5
%10 = phi i8* [ %6, %5 ], [ %8, %7 ], [ %0, %3 ]
%11 = phi double [ -1.000000e+00, %5 ], [ 1.000000e+00, %7 ], [ 1.000000e+00, %3 ]
%12 = load i8, i8* %10
%13 = tail call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %9, %15
%16 = phi double [ %24, %15 ], [ 0.000000e+00, %9 ]
%17 = phi i8* [ %19, %15 ], [ %10, %9 ]
%18 = fmul double %16, 1.000000e+01
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = load i8, i8* %17
%21 = sext i8 %20 to i32
%22 = add nsw i32 %21, -48
%23 = sitofp i32 %22 to double
%24 = fadd double %18, %23
%25 = load i8, i8* %19
%26 = tail call i64 @isdigit(i8 signext %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %15, %9
%29 = phi double [ 0.000000e+00, %9 ], [ %24, %15 ]
%30 = tail call i64 @ms2deg(i32 %1, float %2)
%31 = sitofp i64 %30 to double
%32 = fadd double %29, %31
%33 = fmul double %11, %32
ret double %33
}