#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 termios {
  int c_cflag;
  int *c_cc;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  int /*<<< orphan*/ c_iflag;
};
typedef int /*<<< orphan*/ newtio;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ bzero(struct termios *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
main() {
  int fd, c, res;
  struct termios oldtio, newtio;
  char buf[255];
  fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
  if (fd < 0) {
    perror("/dev/ttyUSB0");
    exit(-1);
  }
  tcgetattr(fd, &oldtio);
  bzero(&newtio, sizeof(newtio));
  newtio.c_cflag = B9600 | CRTSCTS | CS8 | CLOCAL | CREAD;
  newtio.c_iflag = IGNPAR;
  newtio.c_oflag = 0;
  newtio.c_lflag = 0;
  newtio.c_cc[VTIME] = 0;
  newtio.c_cc[VMIN] = 5;
  tcflush(fd, TCIFLUSH);
  tcsetattr(fd, TCSANOW, &newtio);
  int n = 0;
  char fileName[16] = "gpsReadings.txt";
  FILE *f = fopen(fileName, "w");
  while (n < 60) {
    res = read(fd, buf, 254);
    buf[res] = 0;
    fputs(buf, f);
    ++n;
  }
  printf("%s\n", "GPS data save to file!");
  fclose(f);
  tcsetattr(fd, TCSANOW, &oldtio);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2dc6(%rip),%rax
or     (%rax),%esi
lea    0xe15(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1213 <main+0x53>
lea    0xdfc(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
call   1080 <tcgetattr@plt>
lea    -0x60(%rbp),%rdi
mov    $0x28,%esi
call   10d0 <bzero@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
mov    0x2d4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2d82(%rip),%rcx
or     (%rcx),%eax
mov    0x2d31(%rip),%rcx
or     (%rcx),%eax
mov    0x2d78(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x60(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x58(%rbp),%rax
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x58(%rbp),%rax
mov    0x2d27(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    -0x8(%rbp),%edi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0x8(%rbp),%edi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdx
call   1090 <tcsetattr@plt>
movl   $0x0,-0x164(%rbp)
mov    0xd56(%rip),%rax
mov    %rax,-0x180(%rbp)
mov    0xd50(%rip),%rax
mov    %rax,-0x178(%rbp)
lea    -0x180(%rbp),%rdi
lea    0xd10(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x188(%rbp)
cmpl   $0x3c,-0x164(%rbp)
jge    1360 <main+0x1a0>
mov    -0x8(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0xfe,%edx
call   1070 <read@plt>
mov    %eax,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movb   $0x0,-0x160(%rbp,%rax,1)
lea    -0x160(%rbp),%rdi
mov    -0x188(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    1309 <main+0x149>
lea    0xca8(%rip),%rdi
lea    0xca5(%rip),%rsi
call   1050 <printf@plt>
mov    -0x188(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%edi
mov    0x2c57(%rip),%rax
mov    (%rax),%esi
lea    -0x38(%rbp),%rdx
call   1090 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x160,%rsp
mov    0x2e12(%rip),%rax
mov    0x2dcb(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe18(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     1345 <main+0x185>
mov    %eax,%r15d
lea    0x38(%rsp),%rsi
mov    %eax,%edi
call   1080 <tcgetattr@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x28,%esi
call   10d0 <bzero@plt>
mov    0x2dbb(%rip),%rax
mov    0x2d64(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d99(%rip),%rax
or     (%rax),%ecx
mov    0x2d48(%rip),%rax
or     (%rax),%ecx
mov    0x2d8f(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
mov    0x18(%rsp),%rax
mov    0x2d38(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d47(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1040 <tcflush@plt>
mov    0x2d45(%rip),%r12
mov    (%r12),%esi
mov    %r15d,%edi
mov    %r14,%rdx
call   1090 <tcsetattr@plt>
movaps 0xd7f(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xd51(%rip),%rsi
mov    %rsp,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    $0x3c,%ebx
lea    0x60(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xfe,%edx
call   1070 <read@plt>
cltq
movb   $0x0,0x60(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <fputs@plt>
add    $0xffffffff,%ebx
jne    12e0 <main+0x120>
lea    0xd01(%rip),%rdi
lea    0xcfe(%rip),%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    (%r12),%esi
lea    0x38(%rsp),%rdx
mov    %r15d,%edi
call   1090 <tcsetattr@plt>
xor    %eax,%eax
add    $0x160,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb4(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B9600 = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@__const.main.fileName = [16 x i8] c"gpsReadings.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [23 x i8] c"GPS data save to file!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
%6 = alloca %struct.termios
%7 = alloca [255 x i8]
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca i32*
store i32 0, i32* %1
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @O_NOCTTY
%13 = or i32 %11, %12
%14 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %0
%21 = load i32, i32* %2
%22 = call i32 @tcgetattr(i32 %21, %struct.termios* %5)
%23 = call i32 @bzero(%struct.termios* %6, i32 40)
%24 = load i32, i32* @B9600
%25 = load i32, i32* @CRTSCTS
%26 = or i32 %24, %25
%27 = load i32, i32* @CS8
%28 = or i32 %26, %27
%29 = load i32, i32* @CLOCAL
%30 = or i32 %28, %29
%31 = load i32, i32* @CREAD
%32 = or i32 %30, %31
%33 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* @IGNPAR
%35 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 4
store i32 %34, i32* %35
%36 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
store i64 0, i64* %36
%37 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
store i64 0, i64* %37
%38 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%39 = load i32*, i32** %38
%40 = load i64, i64* @VTIME
%41 = getelementptr inbounds i32, i32* %39, i64 %40
store i32 0, i32* %41
%42 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
%43 = load i32*, i32** %42
%44 = load i64, i64* @VMIN
%45 = getelementptr inbounds i32, i32* %43, i64 %44
store i32 5, i32* %45
%46 = load i32, i32* %2
%47 = load i32, i32* @TCIFLUSH
%48 = call i32 @tcflush(i32 %46, i32 %47)
%49 = load i32, i32* %2
%50 = load i32, i32* @TCSANOW
%51 = call i32 @tcsetattr(i32 %49, i32 %50, %struct.termios* %6)
store i32 0, i32* %8
%52 = bitcast [16 x i8]* %9 to i8*
%53 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %54, i32** %10
br label %55
55: ; preds = %58, %20
%56 = load i32, i32* %8
%57 = icmp slt i32 %56, 60
br i1 %57, label %58, label %70
58: ; preds = %55
%59 = load i32, i32* %2
%60 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%61 = call i32 @read(i32 %59, i8* %60, i32 254)
store i32 %61, i32* %4
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 %63
store i8 0, i8* %64
%65 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%66 = load i32*, i32** %10
%67 = call i32 @fputs(i8* %65, i32* %66)
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
store i32 %69, i32* %8
br label %55
70: ; preds = %55
%71 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%72 = load i32*, i32** %10
%73 = call i32 @fclose(i32* %72)
%74 = load i32, i32* %2
%75 = load i32, i32* @TCSANOW
%76 = call i32 @tcsetattr(i32 %74, i32 %75, %struct.termios* %5)
%77 = load i32, i32* %1
ret i32 %77
}

LLVM IR (-O2):
%struct.termios = type { i32, i32*, i64, i64, i32 }
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B9600 = global i32 0
@CRTSCTS = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@VTIME = global i64 0
@VMIN = global i64 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@__const.main.fileName = [16 x i8] c"gpsReadings.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [23 x i8] c"GPS data save to file!\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = alloca [255 x i8]
%4 = alloca [16 x i8]
%5 = bitcast %struct.termios* %1 to i8*
%6 = bitcast %struct.termios* %2 to i8*
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @O_NOCTTY
%10 = or i32 %9, %8
%11 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %0
%17 = call i32 @tcgetattr(i32 %11, %struct.termios* %1)
%18 = call i32 @bzero(%struct.termios* %2, i32 40)
%19 = load i32, i32* @B9600
%20 = load i32, i32* @CRTSCTS
%21 = or i32 %20, %19
%22 = load i32, i32* @CS8
%23 = or i32 %21, %22
%24 = load i32, i32* @CLOCAL
%25 = or i32 %23, %24
%26 = load i32, i32* @CREAD
%27 = or i32 %25, %26
%28 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @IGNPAR
%30 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%32 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%33 = bitcast i64* %31 to i8*
%34 = load i32*, i32** %32
%35 = load i64, i64* @VTIME
%36 = getelementptr inbounds i32, i32* %34, i64 %35
store i32 0, i32* %36
%37 = load i64, i64* @VMIN
%38 = getelementptr inbounds i32, i32* %34, i64 %37
store i32 5, i32* %38
%39 = load i32, i32* @TCIFLUSH
%40 = call i32 @tcflush(i32 %11, i32 %39)
%41 = load i32, i32* @TCSANOW
%42 = call i32 @tcsetattr(i32 %11, i32 %41, %struct.termios* %2)
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %16, %45
%46 = phi i32 [ 0, %16 ], [ %51, %45 ]
%47 = call i32 @read(i32 %11, i8* %7, i32 254)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %48
store i8 0, i8* %49
%50 = call i32 @fputs(i8* %7, i32* %44)
%51 = add nuw nsw i32 %46, 1
%52 = icmp eq i32 %51, 60
br i1 %52, label %53, label %45
53: ; preds = %45
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @fclose(i32* %44)
%56 = load i32, i32* @TCSANOW
%57 = call i32 @tcsetattr(i32 %11, i32 %56, %struct.termios* %1)
ret i32 0
}