#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 sscanf(char *, char *, int *, int *, int *);
void MAG_DMSstringToDegree(char *DMSstring, double *DegreesOfArc) {
  int second, minute, degree, sign = 1, j = 0;
  j = sscanf(DMSstring, "%d, %d, %d", &degree, &minute, &second);
  if (j != 3)
    sscanf(DMSstring, "%d %d %d", &degree, &minute, &second);
  if (degree < 0)
    sign = -1;
  degree = degree * sign;
  *DegreesOfArc = sign * (degree + minute / 60.0 + second / 3600.0);
}


x86 assembly (clang, -O0):
<MAG_DMSstringToDegree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed7(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1030 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
je     1173 <MAG_DMSstringToDegree+0x63>
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1030 <sscanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1184 <MAG_DMSstringToDegree+0x74>
movl   $0xffffffff,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
cvtsi2sdl -0x18(%rbp),%xmm2
movsd  0xe63(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
movsd  0xe46(%rip),%xmm3
divsd  %xmm3,%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAG_DMSstringToDegree>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeec(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x14(%rsp),%r8
call   1030 <sscanf@plt>
cmp    $0x3,%eax
je     115b <MAG_DMSstringToDegree+0x4b>
lea    0xed7(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x14(%rsp),%r8
mov    %rbx,%rdi
call   1030 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
sar    $0x1f,%ecx
or     $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %ecx,%xmm0
cvtsi2sd %eax,%xmm1
cvtsi2sdl 0x10(%rsp),%xmm2
divsd  0xe80(%rip),%xmm2
cvtsi2sdl 0x14(%rsp),%xmm3
divsd  0xe7a(%rip),%xmm3
addsd  %xmm1,%xmm2
addsd  %xmm2,%xmm3
mulsd  %xmm0,%xmm3
movsd  %xmm3,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"%d, %d, %d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
define void @MAG_DMSstringToDegree(i8* %0, double* %1) {
%3 = alloca i8*
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store double* %1, double** %4
store i32 1, i32* %8
store i32 0, i32* %9
%10 = load i8*, i8** %3
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %6, i32* %5)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %6, i32* %5)
br label %17
17: ; preds = %14, %2
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %8
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %7
%23 = load i32, i32* %8
%24 = mul nsw i32 %22, %23
store i32 %24, i32* %7
%25 = load i32, i32* %8
%26 = sitofp i32 %25 to double
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = load i32, i32* %6
%30 = sitofp i32 %29 to double
%31 = fdiv double %30, 6.000000e+01
%32 = fadd double %28, %31
%33 = load i32, i32* %5
%34 = sitofp i32 %33 to double
%35 = fdiv double %34, 3.600000e+03
%36 = fadd double %32, %35
%37 = fmul double %26, %36
%38 = load double*, double** %4
store double %37, double* %38
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"%d, %d, %d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
define void @MAG_DMSstringToDegree(i8* nocapture %0, double* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %4, i32* %3)
%10 = icmp eq i32 %9, 3
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %4, i32* %3)
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %5
%15 = icmp sgt i32 %14, -1
%16 = select i1 %15, i32 1, i32 -1
%17 = mul nsw i32 %16, %14
%18 = sitofp i32 %16 to double
%19 = sitofp i32 %17 to double
%20 = load i32, i32* %4
%21 = sitofp i32 %20 to double
%22 = fdiv double %21, 6.000000e+01
%23 = fadd double %22, %19
%24 = load i32, i32* %3
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 3.600000e+03
%27 = fadd double %23, %26
%28 = fmul double %27, %18
store double %28, double* %1
ret void
}