#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ B500000;
int /*<<< orphan*/ B9600;
int atoi(unsigned char *);
int /*<<< orphan*/ close(int);
int configure_tty(char *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sscanf(int *, char *, unsigned char **, unsigned char **,
                          unsigned char **);
scalar_t__ strncmp(int *, char *, int);
int write(int, int *, int);
int main(int argc, char *argv[]) {
  int GPS_fd = 0;
  int M3_fd = 0;
  int line = 0;
  int gotnewline = 0;
  int fullline = 0;
  int linelength = 0;
  int gottime = 0;
  int n_chars;
  int hours, minutes, seconds;
  uint32_t secondsSinceMidnight;
  unsigned char hours_string[2];
  unsigned char minutes_string[2];
  unsigned char seconds_string[2];
  uint8_t rx_buff[256];
  uint8_t tx_buff[256];
  char *M3_path = "/dev/ttyA8_M3";
  char *GPS_path = "/dev/ttyO1";
  char rxchar;
  int ret;
  if ((GPS_fd = configure_tty(GPS_path, B9600)) <= 0) {
    printf("Could not open and configure TTY %s\n", GPS_path);
    close(GPS_fd);
    return -1;
  }
  if ((M3_fd = configure_tty(M3_path, B500000)) <= 0) {
    printf("Could not open and configure TTY %s\n", M3_path);
    close(M3_fd);
    return -1;
  }
  while (!gotnewline) {
    n_chars = read(GPS_fd, &rxchar, 1);
    if (n_chars = 1 && rxchar == '$') {
      gotnewline = 1;
    }
  }
  while (!gottime) {
    while (!fullline) {
      n_chars = read(GPS_fd, &rxchar, 1);
      if (n_chars == 1 && rxchar == '$') {
        fullline = 1;
        rx_buff[linelength] = 0;
      } else {
        if (n_chars == 1) {
          rx_buff[linelength] = rxchar;
          linelength++;
        }
      }
    }
    linelength = 0;
    fullline = 0;
    if (strncmp(rx_buff, "GPGGA", 5) == 0) {
      sscanf(rx_buff, "GPGGA,%2s%2s%2s", &hours_string, &minutes_string,
             &seconds_string);
      hours = atoi(hours_string);
      minutes = atoi(minutes_string);
      seconds = atoi(seconds_string);
      secondsSinceMidnight = hours * 3600 + minutes * 60 + seconds;
      printf("Got %02d:%02d:%02d from GPS, sending %d to the M3\n", hours,
             minutes, seconds, secondsSinceMidnight);
      gottime = 1;
    }
  }
  tx_buff[0] = 0x16;
  tx_buff[1] = 0x3;
  memcpy(tx_buff + 2, &secondsSinceMidnight, 4);
  if (write(M3_fd, tx_buff, 6) != 6)
    printf("Error writing to %s\n", GPS_path);
  printf("wrote %02x  %02x  %02x  %02x\n", tx_buff[2], tx_buff[3], tx_buff[4],
         tx_buff[5]);
  close(M3_fd);
  close(GPS_fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    0xe1f(%rip),%rax
mov    %rax,-0x858(%rbp)
lea    0xe1f(%rip),%rax
mov    %rax,-0x860(%rbp)
mov    -0x860(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   1070 <configure_tty@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     1240 <main+0xb0>
mov    -0x860(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e1 <main+0x351>
mov    -0x858(%rbp),%rdi
mov    0x2d8a(%rip),%rax
mov    (%rax),%esi
call   1070 <configure_tty@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     128a <main+0xfa>
mov    -0x858(%rbp),%rsi
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e1 <main+0x351>
jmp    128f <main+0xff>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12a5 <main+0x115>
jmp    12ed <main+0x15d>
mov    -0x14(%rbp),%edi
lea    -0x861(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %eax,-0x30(%rbp)
movsbl -0x861(%rbp),%eax
cmp    $0x24,%eax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x30(%rbp)
test   $0x1,%al
jne    12e1 <main+0x151>
jmp    12e8 <main+0x158>
movl   $0x1,-0x20(%rbp)
jmp    128f <main+0xff>
jmp    12f2 <main+0x162>
cmpl   $0x0,-0x2c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1308 <main+0x178>
jmp    144b <main+0x2bb>
jmp    130d <main+0x17d>
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1323 <main+0x193>
jmp    139e <main+0x20e>
mov    -0x14(%rbp),%edi
lea    -0x861(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1,-0x30(%rbp)
jne    136f <main+0x1df>
movsbl -0x861(%rbp),%eax
cmp    $0x24,%eax
jne    136f <main+0x1df>
movl   $0x1,-0x24(%rbp)
movslq -0x28(%rbp),%rax
movl   $0x0,-0x450(%rbp,%rax,4)
jmp    1399 <main+0x209>
cmpl   $0x1,-0x30(%rbp)
jne    1394 <main+0x204>
movsbl -0x861(%rbp),%ecx
movslq -0x28(%rbp),%rax
mov    %ecx,-0x450(%rbp,%rax,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1399 <main+0x209>
jmp    130d <main+0x17d>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x450(%rbp),%rdi
lea    0xc84(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1446 <main+0x2b6>
lea    -0x450(%rbp),%rdi
lea    -0x42(%rbp),%rdx
lea    -0x44(%rbp),%rcx
lea    -0x46(%rbp),%r8
lea    0xc5c(%rip),%rsi
call   10a0 <sscanf@plt>
lea    -0x42(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x34(%rbp)
lea    -0x44(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x38(%rbp)
lea    -0x46(%rbp),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
imul   $0xe10,-0x34(%rbp),%eax
imul   $0x3c,-0x38(%rbp),%ecx
add    %ecx,%eax
add    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    -0x3c(%rbp),%ecx
mov    -0x40(%rbp),%r8d
lea    0xc1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    12f2 <main+0x162>
movl   $0x16,-0x850(%rbp)
movl   $0x3,-0x84c(%rbp)
lea    -0x850(%rbp),%rdi
add    $0x8,%rdi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
mov    -0x18(%rbp),%edi
lea    -0x850(%rbp),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
cmp    $0x6,%eax
je     14aa <main+0x31a>
mov    -0x860(%rbp),%rsi
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x848(%rbp),%esi
mov    -0x844(%rbp),%edx
mov    -0x840(%rbp),%ecx
mov    -0x83c(%rbp),%r8d
lea    0xbd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x870,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe5d(%rip),%rdi
call   1070 <configure_tty@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    13a4 <main+0x214>
mov    0x2e10(%rip),%rax
mov    (%rax),%esi
lea    0xe2f(%rip),%rdi
call   1070 <configure_tty@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    13be <main+0x22e>
mov    %ebx,0x10(%rsp)
lea    0xf(%rsp),%rbp
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmpb   $0x24,0xf(%rsp)
jne    11f0 <main+0x60>
lea    0xf(%rsp),%rbp
lea    0xe2b(%rip),%r15
lea    0x420(%rsp),%r12
jmp    1243 <main+0xb3>
nopl   (%rax)
movslq %ebx,%rax
movl   $0x0,0x420(%rsp,%rax,4)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12ab <main+0x11b>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    0xf(%rsp),%cl
cmp    $0x1,%eax
sete   %al
jne    1266 <main+0xd6>
xor    %ebx,%ebx
cmp    $0x24,%cl
je     1220 <main+0x90>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
test   $0x1,%al
je     1284 <main+0xf4>
movsbl %cl,%eax
movslq %ebx,%rbx
mov    %eax,0x420(%rsp,%rbx,4)
add    $0x1,%ebx
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
movzbl 0xf(%rsp),%ecx
cmp    $0x1,%eax
sete   %al
jne    1270 <main+0xe0>
cmp    $0x24,%cl
jne    1270 <main+0xe0>
jmp    1220 <main+0x90>
lea    0xd92(%rip),%rsi
lea    0x420(%rsp),%rdi
lea    0x1e(%rsp),%rbp
lea    0x1c(%rsp),%r15
lea    0x1a(%rsp),%r12
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   10a0 <sscanf@plt>
mov    %rbp,%rdi
call   10b0 <atoi@plt>
mov    %eax,%r13d
mov    %r15,%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   10b0 <atoi@plt>
imul   $0xe10,%r13d,%ecx
imul   $0x3c,%ebp,%r8d
add    %ecx,%r8d
add    %eax,%r8d
mov    %r8d,0x14(%rsp)
lea    0xd43(%rip),%rdi
xor    %r15d,%r15d
mov    %r13d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
movabs $0x300000016,%rax
mov    %rax,0x20(%rsp)
lea    0x28(%rsp),%rdi
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
call   1090 <memcpy@plt>
lea    0x20(%rsp),%rsi
mov    0x10(%rsp),%ebx
mov    %ebx,%edi
mov    $0x6,%edx
call   1040 <write@plt>
cmp    $0x6,%eax
je     1374 <main+0x1e4>
lea    0xd21(%rip),%rdi
lea    0xca1(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x28(%rsp),%esi
mov    0x2c(%rsp),%edx
mov    0x30(%rsp),%ecx
mov    0x34(%rsp),%r8d
lea    0xd10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
jmp    13e0 <main+0x250>
lea    0xc6e(%rip),%rdi
lea    0xc5c(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
jmp    13d5 <main+0x245>
lea    0xc54(%rip),%rdi
lea    0xc34(%rip),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/ttyA8_M3\00"
@.str.1 = [11 x i8] c"/dev/ttyO1\00"
@B9600 = global i32 0
@.str.2 = [37 x i8] c"Could not open and configure TTY %s\0A\00"
@B500000 = global i32 0
@.str.3 = [6 x i8] c"GPGGA\00"
@.str.4 = [16 x i8] c"GPGGA,%2s%2s%2s\00"
@.str.5 = [51 x i8] c"Got %02d:%02d:%02d from GPS, sending %d to the M3\0A\00"
@.str.6 = [21 x i8] c"Error writing to %s\0A\00"
@.str.7 = [30 x i8] c"wrote %02x %02x %02x %02x\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [2 x i8]
%19 = alloca [2 x i8]
%20 = alloca [2 x i8]
%21 = alloca [256 x i32]
%22 = alloca [256 x i32]
%23 = alloca i8*
%24 = alloca i8*
%25 = alloca i8
%26 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %23
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %24
%27 = load i8*, i8** %24
%28 = load i32, i32* @B9600
%29 = call i32 @configure_tty(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %2
%32 = load i8*, i8** %24
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
store i32 -1, i32* %3
br label %152
36: ; preds = %2
%37 = load i8*, i8** %23
%38 = load i32, i32* @B500000
%39 = call i32 @configure_tty(i8* %37, i32 %38)
store i32 %39, i32* %7
%40 = icmp sle i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %36
%42 = load i8*, i8** %23
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
store i32 -1, i32* %3
br label %152
46: ; preds = %36
br label %47
47: ; preds = %59, %46
%48 = load i32, i32* %9
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br i1 %50, label %51, label %60
51: ; preds = %47
%52 = load i32, i32* %6
%53 = call i32 @read(i32 %52, i8* %25, i32 1)
store i32 %53, i32* %13
%54 = load i8, i8* %25
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 36
%57 = zext i1 %56 to i32
store i32 %57, i32* %13
br i1 %56, label %58, label %59
58: ; preds = %51
store i32 1, i32* %9
br label %59
59: ; preds = %58, %51
br label %47
60: ; preds = %47
br label %61
61: ; preds = %124, %60
%62 = load i32, i32* %12
%63 = icmp ne i32 %62, 0
%64 = xor i1 %63, true
br i1 %64, label %65, label %125
65: ; preds = %61
br label %66
66: ; preds = %95, %65
%67 = load i32, i32* %10
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br i1 %69, label %70, label %96
70: ; preds = %66
%71 = load i32, i32* %6
%72 = call i32 @read(i32 %71, i8* %25, i32 1)
store i32 %72, i32* %13
%73 = load i32, i32* %13
%74 = icmp eq i32 %73, 1
br i1 %74, label %75, label %83
75: ; preds = %70
%76 = load i8, i8* %25
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 36
br i1 %78, label %79, label %83
79: ; preds = %75
store i32 1, i32* %10
%80 = load i32, i32* %11
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 %81
store i32 0, i32* %82
br label %95
83: ; preds = %75, %70
%84 = load i32, i32* %13
%85 = icmp eq i32 %84, 1
br i1 %85, label %86, label %94
86: ; preds = %83
%87 = load i8, i8* %25
%88 = sext i8 %87 to i32
%89 = load i32, i32* %11
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 %90
store i32 %88, i32* %91
%92 = load i32, i32* %11
%93 = add nsw i32 %92, 1
store i32 %93, i32* %11
br label %94
94: ; preds = %86, %83
br label %95
95: ; preds = %94, %79
br label %66
96: ; preds = %66
store i32 0, i32* %11
store i32 0, i32* %10
%97 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 0
%98 = call i64 @strncmp(i32* %97, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%99 = icmp eq i64 %98, 0
br i1 %99, label %100, label %124
100: ; preds = %96
%101 = getelementptr inbounds [256 x i32], [256 x i32]* %21, i64 0, i64 0
%102 = bitcast [2 x i8]* %18 to i8**
%103 = bitcast [2 x i8]* %19 to i8**
%104 = bitcast [2 x i8]* %20 to i8**
%105 = call i32 @sscanf(i32* %101, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8** %102, i8** %103, i8** %104)
%106 = getelementptr inbounds [2 x i8], [2 x i8]* %18, i64 0, i64 0
%107 = call i32 @atoi(i8* %106)
store i32 %107, i32* %14
%108 = getelementptr inbounds [2 x i8], [2 x i8]* %19, i64 0, i64 0
%109 = call i32 @atoi(i8* %108)
store i32 %109, i32* %15
%110 = getelementptr inbounds [2 x i8], [2 x i8]* %20, i64 0, i64 0
%111 = call i32 @atoi(i8* %110)
store i32 %111, i32* %16
%112 = load i32, i32* %14
%113 = mul nsw i32 %112, 3600
%114 = load i32, i32* %15
%115 = mul nsw i32 %114, 60
%116 = add nsw i32 %113, %115
%117 = load i32, i32* %16
%118 = add nsw i32 %116, %117
store i32 %118, i32* %17
%119 = load i32, i32* %14
%120 = load i32, i32* %15
%121 = load i32, i32* %16
%122 = load i32, i32* %17
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %119, i32 %120, i32 %121, i32 %122)
store i32 1, i32* %12
br label %124
124: ; preds = %100, %96
br label %61
125: ; preds = %61
%126 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 0
store i32 22, i32* %126
%127 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 1
store i32 3, i32* %127
%128 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 0
%129 = getelementptr inbounds i32, i32* %128, i64 2
%130 = call i32 @memcpy(i32* %129, i32* %17, i32 4)
%131 = load i32, i32* %7
%132 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 0
%133 = call i32 @write(i32 %131, i32* %132, i32 6)
%134 = icmp ne i32 %133, 6
br i1 %134, label %135, label %138
135: ; preds = %125
%136 = load i8*, i8** %24
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %136)
br label %138
138: ; preds = %135, %125
%139 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 2
%140 = load i32, i32* %139
%141 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 3
%142 = load i32, i32* %141
%143 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 4
%144 = load i32, i32* %143
%145 = getelementptr inbounds [256 x i32], [256 x i32]* %22, i64 0, i64 5
%146 = load i32, i32* %145
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %140, i32 %142, i32 %144, i32 %146)
%148 = load i32, i32* %7
%149 = call i32 @close(i32 %148)
%150 = load i32, i32* %6
%151 = call i32 @close(i32 %150)
br label %152
152: ; preds = %138, %41, %31
%153 = load i32, i32* %3
ret i32 %153
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/ttyA8_M3\00"
@.str.1 = [11 x i8] c"/dev/ttyO1\00"
@B9600 = global i32 0
@.str.2 = [37 x i8] c"Could not open and configure TTY %s\0A\00"
@B500000 = global i32 0
@.str.3 = [6 x i8] c"GPGGA\00"
@.str.4 = [16 x i8] c"GPGGA,%2s%2s%2s\00"
@.str.5 = [51 x i8] c"Got %02d:%02d:%02d from GPS, sending %d to the M3\0A\00"
@.str.6 = [21 x i8] c"Error writing to %s\0A\00"
@.str.7 = [30 x i8] c"wrote %02x %02x %02x %02x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [2 x i8]
%5 = alloca [2 x i8]
%6 = alloca [2 x i8]
%7 = alloca [256 x i32]
%8 = alloca [256 x i32]
%9 = alloca i8
%10 = bitcast i32* %3 to i8*
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%14 = bitcast [256 x i32]* %7 to i8*
%15 = bitcast [256 x i32]* %8 to i8*
%16 = load i32, i32* @B9600
%17 = tail call i32 @configure_tty(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @close(i32 %17)
br label %95
22: ; preds = %2
%23 = load i32, i32* @B500000
%24 = tail call i32 @configure_tty(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = icmp slt i32 %24, 1
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @close(i32 %24)
br label %95
29: ; preds = %34
%30 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 0
%31 = bitcast [2 x i8]* %4 to i8**
%32 = bitcast [2 x i8]* %5 to i8**
%33 = bitcast [2 x i8]* %6 to i8**
br label %38
34: ; preds = %22, %34
%35 = call i32 @read(i32 %17, i8* %9, i32 1)
%36 = load i8, i8* %9
%37 = icmp eq i8 %36, 36
br i1 %37, label %29, label %34
38: ; preds = %60, %29
%39 = call i32 @read(i32 %17, i8* %9, i32 1)
%40 = icmp eq i32 %39, 1
%41 = load i8, i8* %9
%42 = icmp eq i8 %41, 36
%43 = select i1 %40, i1 %42, i1 false
br i1 %43, label %60, label %44
44: ; preds = %38, %53
%45 = phi i8 [ %57, %53 ], [ %41, %38 ]
%46 = phi i1 [ %56, %53 ], [ %40, %38 ]
%47 = phi i32 [ %54, %53 ], [ 0, %38 ]
br i1 %46, label %48, label %53
48: ; preds = %44
%49 = sext i8 %45 to i32
%50 = sext i32 %47 to i64
%51 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 %50
store i32 %49, i32* %51
%52 = add nsw i32 %47, 1
br label %53
53: ; preds = %44, %48
%54 = phi i32 [ %52, %48 ], [ %47, %44 ]
%55 = call i32 @read(i32 %17, i8* %9, i32 1)
%56 = icmp eq i32 %55, 1
%57 = load i8, i8* %9
%58 = icmp eq i8 %57, 36
%59 = select i1 %56, i1 %58, i1 false
br i1 %59, label %60, label %44
60: ; preds = %53, %38
%61 = phi i32 [ 0, %38 ], [ %54, %53 ]
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 %62
store i32 0, i32* %63
%64 = call i64 @strncmp(i32* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %38
66: ; preds = %60
%67 = call i32 @sscanf(i32* %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8** %31, i8** %32, i8** %33)
%68 = call i32 @atoi(i8* %11)
%69 = call i32 @atoi(i8* %12)
%70 = call i32 @atoi(i8* %13)
%71 = mul nsw i32 %68, 3600
%72 = mul nsw i32 %69, 60
%73 = add nsw i32 %72, %71
%74 = add nsw i32 %73, %70
store i32 %74, i32* %3
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %68, i32 %69, i32 %70, i32 %74)
%76 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 0
store i32 22, i32* %76
%77 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 1
store i32 3, i32* %77
%78 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 2
%79 = call i32 @memcpy(i32* %78, i32* %3, i32 4)
%80 = call i32 @write(i32 %24, i32* %76, i32 6)
%81 = icmp eq i32 %80, 6
br i1 %81, label %84, label %82
82: ; preds = %66
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %84
84: ; preds = %82, %66
%85 = load i32, i32* %78
%86 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 3
%87 = load i32, i32* %86
%88 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 4
%89 = load i32, i32* %88
%90 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 5
%91 = load i32, i32* %90
%92 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.7, i64 0, i64 0), i32 %85, i32 %87, i32 %89, i32 %91)
%93 = call i32 @close(i32 %24)
%94 = call i32 @close(i32 %17)
br label %95
95: ; preds = %84, %26, %19
%96 = phi i32 [ -1, %19 ], [ -1, %26 ], [ 0, %84 ]
ret i32 %96
}