#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_iflag;
  int c_lflag;
  int c_oflag;
  int c_cflag;
  int *c_cc;
};

/* Variables and functions */
int NCCS;
int O_NOCTTY;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int main(int argc, char *argv[]) {
  int i, fd;
  struct termios ttyset;
  if (argc < 1) {
    printf("usage ./testSerial /dev/ttyS0\n");
    exit(1);
  }
  fd = open(argv[1], O_RDWR | O_NOCTTY | O_NONBLOCK);
  fgetc(stdin);
  tcgetattr(fd, &ttyset);
  fprintf(stderr, "c_iflag=%#x\n", ttyset.c_iflag);
  fprintf(stderr, "c_lflag=%#x\n", ttyset.c_lflag);
  fprintf(stderr, "c_oflag=%#x\n", ttyset.c_oflag);
  fprintf(stderr, "c_cflag=%#x\n", ttyset.c_cflag);
  fprintf(stderr, "c_cc[]: ");
  for (i = 0; i < NCCS; i++) {
    fprintf(stderr, "%d=%x ", i, ttyset.c_cc[i]);
  }
  fprintf(stderr, "\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1196 <main+0x36>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    0x2e12(%rip),%rax
or     (%rax),%esi
mov    0x2e21(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    -0x18(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
lea    0xe31(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xe17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%eax
jge    12a6 <main+0x146>
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1261 <main+0x101>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jg     1185 <main+0x25>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e54(%rip),%rcx
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x8(%rsi),%rdi
mov    0x2e36(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%esi
call   1070 <open@plt>
mov    %eax,%ebx
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1040 <fgetc@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1060 <tcgetattr@plt>
mov    0x2dec(%rip),%r15
mov    (%r15),%edi
mov    (%rsp),%edx
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    0x4(%rsp),%edx
lea    0xe1f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    0x8(%rsp),%edx
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    0xc(%rsp),%edx
lea    0xe0f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2db9(%rip),%r12
cmpl   $0x0,(%r12)
jle    1274 <main+0x114>
lea    0xdf8(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,4),%ecx
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%rbx
movslq (%r12),%rax
cmp    %rax,%rbx
jl     1250 <main+0xf0>
mov    (%r15),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32, i32* }
@.str = [31 x i8] c"usage ./testSerial /dev/ttyS0\0A\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [13 x i8] c"c_iflag=%#x\0A\00"
@.str.2 = [13 x i8] c"c_lflag=%#x\0A\00"
@.str.3 = [13 x i8] c"c_oflag=%#x\0A\00"
@.str.4 = [13 x i8] c"c_cflag=%#x\0A\00"
@.str.5 = [9 x i8] c"c_cc[]: \00"
@NCCS = global i32 0
@.str.6 = [7 x i8] c"%d=%x \00"
@.str.7 = [2 x i8] c"\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 %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_NOCTTY
%20 = or i32 %18, %19
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %20, %21
%23 = call i32 @open(i8* %17, i32 %22)
store i32 %23, i32* %7
%24 = load i32, i32* @stdin
%25 = call i32 @fgetc(i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @tcgetattr(i32 %26, %struct.termios* %8)
%28 = load i32, i32* @stderr
%29 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 1
%34 = load i32, i32* %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @stderr
%37 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 2
%38 = load i32, i32* %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 3
%42 = load i32, i32* %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %42)
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %6
br label %46
46: ; preds = %60, %14
%47 = load i32, i32* %6
%48 = load i32, i32* @NCCS
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %63
50: ; preds = %46
%51 = load i32, i32* @stderr
%52 = load i32, i32* %6
%53 = getelementptr inbounds %struct.termios, %struct.termios* %8, i32 0, i32 4
%54 = load i32*, i32** %53
%55 = load i32, i32* %6
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %54, i64 %56
%58 = load i32, i32* %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %52, i32 %58)
br label %60
60: ; preds = %50
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %46
63: ; preds = %46
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%66 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32, i32* }
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NONBLOCK = global i32 0
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [13 x i8] c"c_iflag=%#x\0A\00"
@.str.2 = [13 x i8] c"c_lflag=%#x\0A\00"
@.str.3 = [13 x i8] c"c_oflag=%#x\0A\00"
@.str.4 = [13 x i8] c"c_cflag=%#x\0A\00"
@.str.5 = [9 x i8] c"c_cc[]: \00"
@NCCS = global i32 0
@.str.6 = [7 x i8] c"%d=%x \00"
@.str.7 = [2 x i8] c"\0A\00"
@str = [30 x i8] c"usage ./testSerial /dev/ttyS0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = icmp slt i32 %0, 1
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDWR
%13 = load i32, i32* @O_NOCTTY
%14 = or i32 %13, %12
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* %11, i32 %16)
%18 = load i32, i32* @stdin
%19 = tail call i32 @fgetc(i32 %18)
%20 = call i32 @tcgetattr(i32 %17, %struct.termios* %3)
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @stderr
%26 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32, i32* @stderr
%30 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%31 = load i32, i32* %30
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stderr
%34 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%35 = load i32, i32* %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @NCCS
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %55
41: ; preds = %9
%42 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 4
br label %43
43: ; preds = %41, %43
%44 = phi i64 [ 0, %41 ], [ %51, %43 ]
%45 = load i32, i32* @stderr
%46 = load i32*, i32** %42
%47 = getelementptr inbounds i32, i32* %46, i64 %44
%48 = load i32, i32* %47
%49 = trunc i64 %44 to i32
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %49, i32 %48)
%51 = add nuw nsw i64 %44, 1
%52 = load i32, i32* @NCCS
%53 = sext i32 %52 to i64
%54 = icmp slt i64 %51, %53
br i1 %54, label %43, label %55
55: ; preds = %43, %9
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
}