#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 dec2bin(char);
int roadmap_nmea_decode_numeric(char *, int);
char *strchr(char *, char);
int strlen(char *);
int roadmap_nmea_decode_coordinate(char *value, char *side, char positive,
                                   char negative) {
  int result;
  char *dot = strchr(value, '.');
  if (dot == NULL) {
    if (value[0] == 0)
      return 0;
    dot = value + strlen(value);
  }
  dot -= 2;
  result = 0;
  while (value < dot) {
    result = dec2bin(*value) + (10 * result);
    value += 1;
  }
  result *= 1000000;
  result += roadmap_nmea_decode_numeric(dot, 1000000) / 60;
  if (side[1] == 0) {
    if (side[0] == negative) {
      return 0 - result;
    }
    if (side[0] == positive) {
      return result;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<roadmap_nmea_decode_coordinate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %cl,-0x19(%rbp)
mov    %al,-0x1a(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b4 <roadmap_nmea_decode_coordinate+0x74>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1193 <roadmap_nmea_decode_coordinate+0x53>
movl   $0x0,-0x4(%rbp)
jmp    127c <roadmap_nmea_decode_coordinate+0x13c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11fb <roadmap_nmea_decode_coordinate+0xbb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1060 <dec2bin@plt>
imul   $0xa,-0x20(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11c7 <roadmap_nmea_decode_coordinate+0x87>
imul   $0xf4240,-0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0xf4240,%esi
call   1050 <roadmap_nmea_decode_numeric@plt>
mov    $0x3c,%ecx
cltd
idiv   %ecx
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1275 <roadmap_nmea_decode_coordinate+0x135>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
jne    1252 <roadmap_nmea_decode_coordinate+0x112>
xor    %eax,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <roadmap_nmea_decode_coordinate+0x13c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
jne    1270 <roadmap_nmea_decode_coordinate+0x130>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    127c <roadmap_nmea_decode_coordinate+0x13c>
jmp    1275 <roadmap_nmea_decode_coordinate+0x135>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roadmap_nmea_decode_coordinate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    117f <roadmap_nmea_decode_coordinate+0x3f>
cmpb   $0x0,(%r15)
je     11f0 <roadmap_nmea_decode_coordinate+0xb0>
mov    %r15,%rdi
call   1030 <strlen@plt>
movslq %eax,%r12
add    %r15,%r12
mov    %rbx,0x10(%rsp)
lea    -0x2(%r12),%r13
xor    %ebx,%ebx
cmp    %r15,%r13
jbe    11d8 <roadmap_nmea_decode_coordinate+0x98>
mov    %r14d,0x8(%rsp)
mov    %ebp,0xc(%rsp)
sub    %r15,%r12
add    $0xfffffffffffffffe,%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r15,%rbp,1),%edi
call   1060 <dec2bin@plt>
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%ebx
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11b0 <roadmap_nmea_decode_coordinate+0x70>
imul   $0xf4240,%ebx,%ebx
mov    0xc(%rsp),%ebp
mov    0x8(%rsp),%r14d
mov    %r13,%rdi
mov    $0xf4240,%esi
call   1050 <roadmap_nmea_decode_numeric@plt>
mov    0x10(%rsp),%rdx
cmpb   $0x0,0x1(%rdx)
je     1201 <roadmap_nmea_decode_coordinate+0xc1>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x5,%eax
add    %ecx,%eax
add    %ebx,%eax
mov    (%rdx),%cl
cmp    %r14b,%cl
jne    1227 <roadmap_nmea_decode_coordinate+0xe7>
neg    %eax
jmp    11f2 <roadmap_nmea_decode_coordinate+0xb2>
cmp    %bpl,%cl
jne    11f0 <roadmap_nmea_decode_coordinate+0xb0>
jmp    11f2 <roadmap_nmea_decode_coordinate+0xb2>

LLVM IR (-O0):
define i32 @roadmap_nmea_decode_coordinate(i8* %0, i8* %1, i8 signext %2, i8 signext %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8 %2, i8* %8
store i8 %3, i8* %9
%12 = load i8*, i8** %6
%13 = call i8* @strchr(i8* %12, i8 signext 46)
store i8* %13, i8** %11
%14 = load i8*, i8** %11
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %29
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 0, i32* %5
br label %81
23: ; preds = %16
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8* %28, i8** %11
br label %29
29: ; preds = %23, %4
%30 = load i8*, i8** %11
%31 = getelementptr inbounds i8, i8* %30, i64 -2
store i8* %31, i8** %11
store i32 0, i32* %10
br label %32
32: ; preds = %36, %29
%33 = load i8*, i8** %6
%34 = load i8*, i8** %11
%35 = icmp ult i8* %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i8, i8* %37
%39 = call i32 @dec2bin(i8 signext %38)
%40 = load i32, i32* %10
%41 = mul nsw i32 10, %40
%42 = add nsw i32 %39, %41
store i32 %42, i32* %10
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %6
br label %32
45: ; preds = %32
%46 = load i32, i32* %10
%47 = mul nsw i32 %46, 1000000
store i32 %47, i32* %10
%48 = load i8*, i8** %11
%49 = call i32 @roadmap_nmea_decode_numeric(i8* %48, i32 1000000)
%50 = sdiv i32 %49, 60
%51 = load i32, i32* %10
%52 = add nsw i32 %51, %50
store i32 %52, i32* %10
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %80
58: ; preds = %45
%59 = load i8*, i8** %7
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = load i8, i8* %9
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %62, %64
br i1 %65, label %66, label %69
66: ; preds = %58
%67 = load i32, i32* %10
%68 = sub nsw i32 0, %67
store i32 %68, i32* %5
br label %81
69: ; preds = %58
%70 = load i8*, i8** %7
%71 = getelementptr inbounds i8, i8* %70, i64 0
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = load i8, i8* %8
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %73, %75
br i1 %76, label %77, label %79
77: ; preds = %69
%78 = load i32, i32* %10
store i32 %78, i32* %5
br label %81
79: ; preds = %69
br label %80
80: ; preds = %79, %45
store i32 0, i32* %5
br label %81
81: ; preds = %80, %77, %66, %22
%82 = load i32, i32* %5
ret i32 %82
}

LLVM IR (-O2):
define i32 @roadmap_nmea_decode_coordinate(i8* %0, i8* nocapture %1, i8 signext %2, i8 signext %3) {
%5 = ptrtoint i8* %0 to i64
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %15
8: ; preds = %4
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %51, label %11
11: ; preds = %8
%12 = tail call i32 @strlen(i8* %0)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
br label %15
15: ; preds = %11, %4
%16 = phi i8* [ %14, %11 ], [ %6, %4 ]
%17 = getelementptr inbounds i8, i8* %16, i64 -2
%18 = icmp ugt i8* %17, %0
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = ptrtoint i8* %16 to i64
%21 = add i64 %20, -2
%22 = sub i64 %21, %5
%23 = getelementptr i8, i8* %0, i64 %22
br label %24
24: ; preds = %19, %24
%25 = phi i32 [ %30, %24 ], [ 0, %19 ]
%26 = phi i8* [ %31, %24 ], [ %0, %19 ]
%27 = load i8, i8* %26
%28 = tail call i32 @dec2bin(i8 signext %27)
%29 = mul nsw i32 %25, 10
%30 = add nsw i32 %28, %29
%31 = getelementptr inbounds i8, i8* %26, i64 1
%32 = icmp eq i8* %31, %23
br i1 %32, label %33, label %24
33: ; preds = %24
%34 = mul i32 %30, 1000000
br label %35
35: ; preds = %33, %15
%36 = phi i32 [ 0, %15 ], [ %34, %33 ]
%37 = tail call i32 @roadmap_nmea_decode_numeric(i8* %17, i32 1000000)
%38 = sdiv i32 %37, 60
%39 = add nsw i32 %38, %36
%40 = getelementptr inbounds i8, i8* %1, i64 1
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %35
%44 = load i8, i8* %1
%45 = icmp eq i8 %44, %3
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = sub nsw i32 0, %39
br label %51
48: ; preds = %43
%49 = icmp eq i8 %44, %2
br i1 %49, label %51, label %50
50: ; preds = %48, %35
br label %51
51: ; preds = %48, %8, %50, %46
%52 = phi i32 [ %47, %46 ], [ 0, %50 ], [ 0, %8 ], [ %39, %48 ]
ret i32 %52
}