#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 strcspn(char *, char *);
double to_seconds(char *);
double parse_lonlat(char *llstr) {
  int commaind = strcspn(llstr, ",");
  char *side = llstr + commaind;
  int do_neg = 0;
  double ret;
  if (side[0] == ',') {
    side[0] = 0;
    if ((side[1] == 'S') || (side[1] == 'W')) {
      do_neg = 1;
    }
  }
  ret = to_seconds(llstr) / 3600.0;
  return do_neg ? -ret : ret;
}


x86 assembly (clang, -O0):
<parse_lonlat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
call   1030 <strcspn@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
jne    119a <parse_lonlat+0x7a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x53,%eax
je     118e <parse_lonlat+0x6e>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x57,%eax
jne    1195 <parse_lonlat+0x75>
movl   $0x1,-0x1c(%rbp)
jmp    119a <parse_lonlat+0x7a>
mov    -0x8(%rbp),%rdi
call   1040 <to_seconds@plt>
movsd  0xe55(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11e4 <parse_lonlat+0xc4>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11ee <parse_lonlat+0xce>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_lonlat>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xef3(%rip),%rsi
call   1030 <strcspn@plt>
cltq
cmpb   $0x2c,(%rbx,%rax,1)
jne    1167 <parse_lonlat+0x47>
movb   $0x0,(%rbx,%rax,1)
mov    0x1(%rbx,%rax,1),%bpl
and    $0xfb,%bpl
mov    %rbx,%rdi
call   1040 <to_seconds@plt>
divsd  0xea9(%rip),%xmm0
cmp    $0x53,%bpl
jne    1177 <parse_lonlat+0x57>
xorpd  0xeab(%rip),%xmm0
jmp    1177 <parse_lonlat+0x57>
mov    %rbx,%rdi
call   1040 <to_seconds@plt>
divsd  0xe89(%rip),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define double @parse_lonlat(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca double
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strcspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %3
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
store i8* %12, i8** %4
store i32 0, i32* %5
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 44
br i1 %17, label %18, label %34
18: ; preds = %1
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 0, i8* %20
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 83
br i1 %25, label %32, label %26
26: ; preds = %18
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 87
br i1 %31, label %32, label %33
32: ; preds = %26, %18
store i32 1, i32* %5
br label %33
33: ; preds = %32, %26
br label %34
34: ; preds = %33, %1
%35 = load i8*, i8** %2
%36 = call double @to_seconds(i8* %35)
%37 = fdiv double %36, 3.600000e+03
store double %37, double* %6
%38 = load i32, i32* %5
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %34
%41 = load double, double* %6
%42 = fneg double %41
br label %45
43: ; preds = %34
%44 = load double, double* %6
br label %45
45: ; preds = %43, %40
%46 = phi double [ %42, %40 ], [ %44, %43 ]
ret double %46
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define double @parse_lonlat(i8* %0) {
%2 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 44
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = tail call double @to_seconds(i8* %0)
%9 = fdiv double %8, 3.600000e+03
br label %18
10: ; preds = %1
store i8 0, i8* %4
%11 = getelementptr inbounds i8, i8* %4, i64 1
%12 = load i8, i8* %11
%13 = and i8 %12, -5
%14 = icmp eq i8 %13, 83
%15 = tail call double @to_seconds(i8* %0)
%16 = fdiv double %15, 3.600000e+03
%17 = fneg double %16
br i1 %14, label %20, label %18
18: ; preds = %7, %10
%19 = phi double [ %9, %7 ], [ %16, %10 ]
br label %20
20: ; preds = %10, %18
%21 = phi double [ %19, %18 ], [ %17, %10 ]
ret double %21
}