#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 */
struct pollfd {
  int fd;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *,
           char *, char *, float *, char *, float *, char *, float *, float *,
           unsigned int *, unsigned int *, unsigned int *);
scalar_t__ strncmp(char *, char *, int);
int gps_read(int fd, float *lon, float *lat) {
  int bp;
  int debug = 0;
  float course, speed;
  char foo[6], buf[124], valid, ns, ew;
  int try, res, maxtry = 10;
  unsigned int year, mon, day, hour, min, sec;
  int done = 0;
  for (try = 0; !done && try < maxtry; try++) {
    bp = 0;
    while (bp < 124) {
      int n, ok;
      char b;
      struct pollfd pfd;
      pfd.fd = fd;
      pfd.events = POLLIN;
      ok = poll(&pfd, 1, -1);
      if (ok < 0)
        continue;
      n = read(fd, &b, 1);
      if (n < 0)
        continue;
      buf[bp++] = b;
      if (b == '\n')
        break;
    }
    if (strncmp("$GPRMC", buf, 6) == 0) {
      if (debug)
        printf("%s", buf);
      res =
          sscanf(buf, "$GPRMC,%2d%2d%2d.%3c,%1c,%f,%1c,%f,%1c,%f,%f,%2d%2d%2d",
                 &hour, &min, &sec, foo, &valid, lat, &ns, lon, &ew, &speed,
                 &course, &day, &mon, &year);
      if (res == 14 && valid == 'A') {
        *lat /= 100;
        *lon /= 100;
        if (ns == 'S')
          *lat = -*lat;
        if (ew == 'W')
          *lon = -*lon;
        done = 1;
      }
    }
  }
  if (!done)
    return (-1);
  else
    return 1;
}


x86 assembly (clang, -O0):
<gps_read>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
mov    %edi,-0x30(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdx,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0xa,-0xf0(%rbp)
movl   $0x0,-0x10c(%rbp)
movl   $0x0,-0xe8(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10c(%rbp)
mov    %al,-0x121(%rbp)
jne    11be <gps_read+0x6e>
mov    -0xe8(%rbp),%eax
cmp    -0xf0(%rbp),%eax
setl   %al
mov    %al,-0x121(%rbp)
mov    -0x121(%rbp),%al
test   $0x1,%al
jne    11d1 <gps_read+0x81>
jmp    145d <gps_read+0x30d>
movl   $0x0,-0x44(%rbp)
cmpl   $0x7c,-0x44(%rbp)
jge    1288 <gps_read+0x138>
mov    -0x30(%rbp),%eax
mov    %eax,-0x120(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x120(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1070 <poll@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    1228 <gps_read+0xd8>
jmp    11d8 <gps_read+0x88>
mov    -0x30(%rbp),%edi
lea    -0x115(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x110(%rbp)
cmpl   $0x0,-0x110(%rbp)
jge    1254 <gps_read+0x104>
jmp    11d8 <gps_read+0x88>
mov    -0x115(%rbp),%cl
mov    -0x44(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
cltq
mov    %cl,-0xe0(%rbp,%rax,1)
movsbl -0x115(%rbp),%eax
cmp    $0xa,%eax
jne    1283 <gps_read+0x133>
jmp    1288 <gps_read+0x138>
jmp    11d8 <gps_read+0x88>
lea    -0xe0(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1444 <gps_read+0x2f4>
cmpl   $0x0,-0x48(%rbp)
je     12c7 <gps_read+0x177>
lea    -0xe0(%rbp),%rsi
lea    0xd49(%rip),%rdi
call   1040 <printf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0x56(%rbp),%r9
mov    -0x40(%rbp),%rax
mov    %rax,-0x138(%rbp)
mov    -0x38(%rbp),%r12
lea    0xd26(%rip),%rsi
lea    -0x100(%rbp),%rdx
lea    -0x104(%rbp),%rcx
lea    -0x108(%rbp),%r8
lea    -0xe1(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0xe2(%rbp),%r13
lea    -0xe3(%rbp),%r15
lea    -0x50(%rbp),%r14
lea    -0x4c(%rbp),%rbx
lea    -0xfc(%rbp),%r11
lea    -0xf8(%rbp),%r10
lea    -0xf4(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x140(%rbp),%rax
mov    %rax,(%rsp)
mov    -0x138(%rbp),%rax
mov    %rax,0x8(%rsp)
mov    -0x130(%rbp),%rax
mov    %r13,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    %r14,0x28(%rsp)
mov    %rbx,0x30(%rsp)
mov    %r11,0x38(%rsp)
mov    %r10,0x40(%rsp)
mov    %rax,0x48(%rsp)
call   1060 <sscanf@plt>
mov    %eax,-0xec(%rbp)
cmpl   $0xe,-0xec(%rbp)
jne    143f <gps_read+0x2ef>
movsbl -0xe1(%rbp),%eax
cmp    $0x41,%eax
jne    143f <gps_read+0x2ef>
mov    -0x40(%rbp),%rax
movss  (%rax),%xmm0
movss  0xc45(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
mov    -0x38(%rbp),%rax
movss  (%rax),%xmm0
movss  0xc2d(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
movsbl -0xe2(%rbp),%eax
cmp    $0x53,%eax
jne    1408 <gps_read+0x2b8>
mov    -0x40(%rbp),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x40(%rbp),%rax
movss  %xmm0,(%rax)
movsbl -0xe3(%rbp),%eax
cmp    $0x57,%eax
jne    1435 <gps_read+0x2e5>
mov    -0x38(%rbp),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
mov    -0x38(%rbp),%rax
movss  %xmm0,(%rax)
movl   $0x1,-0x10c(%rbp)
jmp    1444 <gps_read+0x2f4>
jmp    1449 <gps_read+0x2f9>
mov    -0xe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xe8(%rbp)
jmp    1194 <gps_read+0x44>
cmpl   $0x0,-0x10c(%rbp)
jne    1476 <gps_read+0x326>
movl   $0xffffffff,-0x2c(%rbp)
jmp    147d <gps_read+0x32d>
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x168,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<gps_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rdx,0x18(%rsp)
mov    %rsi,0x10(%rsp)
mov    %edi,%ebp
xor    %r12d,%r12d
mov    0x2e81(%rip),%r15
lea    0x20(%rsp),%rbx
lea    0xc(%rsp),%r14
jmp    11b1 <gps_read+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe99(%rip),%rdi
lea    0x50(%rsp),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1220 <gps_read+0xe0>
lea    0x1(%r12),%eax
cmp    $0x9,%r12d
mov    %eax,%r12d
jae    12f7 <gps_read+0x1b7>
xor    %r13d,%r13d
jmp    11c6 <gps_read+0x86>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x7c,%r13d
jge    1180 <gps_read+0x40>
mov    %ebp,0x20(%rsp)
mov    (%r15),%eax
mov    %eax,0x24(%rsp)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1060 <poll@plt>
test   %eax,%eax
js     11c0 <gps_read+0x80>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11c0 <gps_read+0x80>
movzbl 0xc(%rsp),%eax
movslq %r13d,%rcx
mov    %al,0x50(%rsp,%rcx,1)
cmp    $0xa,%al
je     1180 <gps_read+0x40>
add    $0x1,%r13d
jmp    11c0 <gps_read+0x80>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x50(%rsp),%rdi
lea    0xdfb(%rip),%rsi
lea    0x30(%rsp),%rdx
lea    0x2c(%rsp),%rcx
lea    0x28(%rsp),%r8
lea    0x4a(%rsp),%r9
lea    0x3c(%rsp),%rax
push   %rax
lea    0x40(%rsp),%rax
push   %rax
lea    0x44(%rsp),%rax
push   %rax
lea    0x5c(%rsp),%rax
push   %rax
lea    0x60(%rsp),%rax
push   %rax
lea    0x35(%rsp),%rax
push   %rax
push   0x40(%rsp)
lea    0x46(%rsp),%rax
push   %rax
push   0x58(%rsp)
lea    0x57(%rsp),%rax
push   %rax
call   1050 <sscanf@plt>
add    $0x50,%rsp
cmp    $0xe,%eax
jne    119f <gps_read+0x5f>
cmpb   $0x41,0xf(%rsp)
jne    119f <gps_read+0x5f>
mov    0x18(%rsp),%rcx
movss  (%rcx),%xmm0
movss  0xd5a(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,(%rcx)
mov    0x10(%rsp),%rax
movss  (%rax),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,(%rax)
cmpb   $0x53,0xe(%rsp)
jne    12d5 <gps_read+0x195>
movss  (%rcx),%xmm0
xorps  0xd3f(%rip),%xmm0
movss  %xmm0,(%rcx)
mov    $0x1,%eax
cmpb   $0x57,0xd(%rsp)
jne    12fc <gps_read+0x1bc>
mov    0x10(%rsp),%rcx
movss  (%rcx),%xmm0
xorps  0xd1f(%rip),%xmm0
movss  %xmm0,(%rcx)
jmp    12fc <gps_read+0x1bc>
mov    $0xffffffff,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@.str = [7 x i8] c"$GPRMC\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [55 x i8] c"$GPRMC,%2d%2d%2d.%3c,%1c,%f,%1c,%f,%1c,%f,%f,%2d%2d%2d\00"
define i32 @gps_read(i32 %0, float* %1, float* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca float*
%7 = alloca float*
%8 = alloca i32
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca [6 x i8]
%13 = alloca [124 x i8]
%14 = alloca i8
%15 = alloca i8
%16 = alloca i8
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i8
%30 = alloca %struct.pollfd
store i32 %0, i32* %5
store float* %1, float** %6
store float* %2, float** %7
store i32 0, i32* %9
store i32 10, i32* %19
store i32 0, i32* %26
store i32 0, i32* %17
br label %31
31: ; preds = %119, %3
%32 = load i32, i32* %26
%33 = icmp ne i32 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* %17
%36 = load i32, i32* %19
%37 = icmp slt i32 %35, %36
br label %38
38: ; preds = %34, %31
%39 = phi i1 [ false, %31 ], [ %37, %34 ]
br i1 %39, label %40, label %122
40: ; preds = %38
store i32 0, i32* %8
br label %41
41: ; preds = %69, %58, %52, %40
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 124
br i1 %43, label %44, label %70
44: ; preds = %41
%45 = load i32, i32* %5
%46 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 0
store i32 %45, i32* %46
%47 = load i32, i32* @POLLIN
%48 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 1
store i32 %47, i32* %48
%49 = call i32 @poll(%struct.pollfd* %30, i32 1, i32 -1)
store i32 %49, i32* %28
%50 = load i32, i32* %28
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %44
br label %41
53: ; preds = %44
%54 = load i32, i32* %5
%55 = call i32 @read(i32 %54, i8* %29, i32 1)
store i32 %55, i32* %27
%56 = load i32, i32* %27
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %53
br label %41
59: ; preds = %53
%60 = load i8, i8* %29
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
%63 = sext i32 %61 to i64
%64 = getelementptr inbounds [124 x i8], [124 x i8]* %13, i64 0, i64 %63
store i8 %60, i8* %64
%65 = load i8, i8* %29
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %66, 10
br i1 %67, label %68, label %69
68: ; preds = %59
br label %70
69: ; preds = %59
br label %41
70: ; preds = %68, %41
%71 = getelementptr inbounds [124 x i8], [124 x i8]* %13, i64 0, i64 0
%72 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %71, i32 6)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %118
74: ; preds = %70
%75 = load i32, i32* %9
%76 = icmp ne i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = getelementptr inbounds [124 x i8], [124 x i8]* %13, i64 0, i64 0
%79 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %77, %74
%81 = getelementptr inbounds [124 x i8], [124 x i8]* %13, i64 0, i64 0
%82 = getelementptr inbounds [6 x i8], [6 x i8]* %12, i64 0, i64 0
%83 = load float*, float** %7
%84 = load float*, float** %6
%85 = call i32 @sscanf(i8* %81, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32* %23, i32* %24, i32* %25, i8* %82, i8* %14, float* %83, i8* %15, float* %84, i8* %16, float* %11, float* %10, i32* %22, i32* %21, i32* %20)
store i32 %85, i32* %18
%86 = load i32, i32* %18
%87 = icmp eq i32 %86, 14
br i1 %87, label %88, label %117
88: ; preds = %80
%89 = load i8, i8* %14
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 65
br i1 %91, label %92, label %117
92: ; preds = %88
%93 = load float*, float** %7
%94 = load float, float* %93
%95 = fdiv float %94, 1.000000e+02
store float %95, float* %93
%96 = load float*, float** %6
%97 = load float, float* %96
%98 = fdiv float %97, 1.000000e+02
store float %98, float* %96
%99 = load i8, i8* %15
%100 = sext i8 %99 to i32
%101 = icmp eq i32 %100, 83
br i1 %101, label %102, label %107
102: ; preds = %92
%103 = load float*, float** %7
%104 = load float, float* %103
%105 = fneg float %104
%106 = load float*, float** %7
store float %105, float* %106
br label %107
107: ; preds = %102, %92
%108 = load i8, i8* %16
%109 = sext i8 %108 to i32
%110 = icmp eq i32 %109, 87
br i1 %110, label %111, label %116
111: ; preds = %107
%112 = load float*, float** %6
%113 = load float, float* %112
%114 = fneg float %113
%115 = load float*, float** %6
store float %114, float* %115
br label %116
116: ; preds = %111, %107
store i32 1, i32* %26
br label %117
117: ; preds = %116, %88, %80
br label %118
118: ; preds = %117, %70
br label %119
119: ; preds = %118
%120 = load i32, i32* %17
%121 = add nsw i32 %120, 1
store i32 %121, i32* %17
br label %31
122: ; preds = %38
%123 = load i32, i32* %26
%124 = icmp ne i32 %123, 0
br i1 %124, label %126, label %125
125: ; preds = %122
store i32 -1, i32* %4
br label %127
126: ; preds = %122
store i32 1, i32* %4
br label %127
127: ; preds = %126, %125
%128 = load i32, i32* %4
ret i32 %128
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@.str = [7 x i8] c"$GPRMC\00"
@.str.2 = [55 x i8] c"$GPRMC,%2d%2d%2d.%3c,%1c,%f,%1c,%f,%1c,%f,%f,%2d%2d%2d\00"
define i32 @gps_read(i32 %0, float* %1, float* %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca [6 x i8]
%7 = alloca [124 x i8]
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8
%18 = alloca %struct.pollfd
%19 = bitcast float* %4 to i8*
%20 = bitcast float* %5 to i8*
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [124 x i8], [124 x i8]* %7, i64 0, i64 0
%23 = bitcast i32* %11 to i8*
%24 = bitcast i32* %12 to i8*
%25 = bitcast i32* %13 to i8*
%26 = bitcast i32* %14 to i8*
%27 = bitcast i32* %15 to i8*
%28 = bitcast i32* %16 to i8*
%29 = bitcast %struct.pollfd* %18 to i8*
%30 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %18, i64 0, i32 0
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %18, i64 0, i32 1
br label %32
32: ; preds = %3, %77
%33 = phi i32 [ 0, %3 ], [ %78, %77 ]
br label %34
34: ; preds = %32, %49
%35 = phi i32 [ 0, %32 ], [ %50, %49 ]
store i32 %0, i32* %30
%36 = load i32, i32* @POLLIN
store i32 %36, i32* %31
%37 = call i32 @poll(%struct.pollfd* %18, i32 1, i32 -1)
%38 = icmp slt i32 %37, 0
br i1 %38, label %49, label %39
39: ; preds = %34
%40 = call i32 @read(i32 %0, i8* %17, i32 1)
%41 = icmp slt i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %39
%43 = load i8, i8* %17
%44 = add nsw i32 %35, 1
%45 = sext i32 %35 to i64
%46 = getelementptr inbounds [124 x i8], [124 x i8]* %7, i64 0, i64 %45
store i8 %43, i8* %46
%47 = icmp eq i8 %43, 10
br i1 %47, label %48, label %49
48: ; preds = %42
br label %52
49: ; preds = %42, %39, %34
%50 = phi i32 [ %35, %34 ], [ %35, %39 ], [ %44, %42 ]
%51 = icmp slt i32 %50, 124
br i1 %51, label %34, label %52
52: ; preds = %49, %48
%53 = call i64 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %22, i32 6)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %77
55: ; preds = %52
%56 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i32* %14, i32* %15, i32* %16, i8* %21, i8* %8, float* %2, i8* %9, float* %1, i8* %10, float* %5, float* %4, i32* %13, i32* %12, i32* %11)
%57 = icmp eq i32 %56, 14
%58 = load i8, i8* %8
%59 = icmp eq i8 %58, 65
%60 = select i1 %57, i1 %59, i1 false
br i1 %60, label %61, label %77
61: ; preds = %55
%62 = load float, float* %2
%63 = fdiv float %62, 1.000000e+02
store float %63, float* %2
%64 = load float, float* %1
%65 = fdiv float %64, 1.000000e+02
store float %65, float* %1
%66 = load i8, i8* %9
%67 = icmp eq i8 %66, 83
br i1 %67, label %68, label %71
68: ; preds = %61
%69 = load float, float* %2
%70 = fneg float %69
store float %70, float* %2
br label %71
71: ; preds = %68, %61
%72 = load i8, i8* %10
%73 = icmp eq i8 %72, 87
br i1 %73, label %74, label %80
74: ; preds = %71
%75 = load float, float* %1
%76 = fneg float %75
store float %76, float* %1
br label %80
77: ; preds = %52, %55
%78 = add nuw nsw i32 %33, 1
%79 = icmp ult i32 %33, 9
br i1 %79, label %32, label %80
80: ; preds = %77, %74, %71
%81 = phi i32 [ 1, %71 ], [ 1, %74 ], [ -1, %77 ]
ret i32 %81
}