#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
scalar_t__ cfsetispeed(struct termios *, int);
scalar_t__ cfsetospeed(struct termios *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ makeraw(struct termios *, int);
int /*<<< orphan*/ stderr;
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void initSerialPort(int handle, int baud, int bits) {
  struct termios ios;
  if (tcgetattr(handle, &ios) < 0) {
    fprintf(stderr, "Can't get terminal attributes.\n");
    exit(1);
  }
  if (cfsetispeed(&ios, baud) < 0) {
    fprintf(stderr, "Can't set input baud rate.\n");
    exit(1);
  }
  if (cfsetospeed(&ios, baud) < 0) {
    fprintf(stderr, "Can't set output baud rate.\n");
    exit(1);
  }
  makeraw(&ios, bits);
  if (tcsetattr(handle, TCSANOW, &ios) < 0) {
    fprintf(stderr, "Can't set port attributes.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<initSerialPort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0x0,%rax
jge    11b6 <initSerialPort+0x46>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1080 <cfsetispeed@plt>
cmp    $0x0,%rax
jge    11eb <initSerialPort+0x7b>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1030 <cfsetospeed@plt>
cmp    $0x0,%rax
jge    1220 <initSerialPort+0xb0>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%esi
lea    -0x10(%rbp),%rdi
call   1040 <makeraw@plt>
mov    -0x4(%rbp),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
cmp    $0x0,%rax
jge    126a <initSerialPort+0xfa>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initSerialPort>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1060 <tcgetattr@plt>
test   %rax,%rax
js     11e1 <initSerialPort+0x71>
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1080 <cfsetispeed@plt>
test   %rax,%rax
js     11f3 <initSerialPort+0x83>
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1030 <cfsetospeed@plt>
test   %rax,%rax
js     1205 <initSerialPort+0x95>
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    %r14d,%esi
call   1040 <makeraw@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1070 <tcsetattr@plt>
test   %rax,%rax
js     1217 <initSerialPort+0xa7>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
jmp    1227 <initSerialPort+0xb7>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
jmp    1227 <initSerialPort+0xb7>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
jmp    1227 <initSerialPort+0xb7>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Can't get terminal attributes.\0A\00"
@.str.1 = [28 x i8] c"Can't set input baud rate.\0A\00"
@.str.2 = [29 x i8] c"Can't set output baud rate.\0A\00"
@TCSANOW = global i32 0
@.str.3 = [28 x i8] c"Can't set port attributes.\0A\00"
define void @initSerialPort(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = call i64 @tcgetattr(i32 %8, %struct.termios* %7)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %3
%16 = load i32, i32* %5
%17 = call i64 @cfsetispeed(%struct.termios* %7, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = load i32, i32* %5
%25 = call i64 @cfsetospeed(%struct.termios* %7, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
%32 = load i32, i32* %6
%33 = call i32 @makeraw(%struct.termios* %7, i32 %32)
%34 = load i32, i32* %4
%35 = load i32, i32* @TCSANOW
%36 = call i64 @tcsetattr(i32 %34, i32 %35, %struct.termios* %7)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %31
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Can't get terminal attributes.\0A\00"
@.str.1 = [28 x i8] c"Can't set input baud rate.\0A\00"
@.str.2 = [29 x i8] c"Can't set output baud rate.\0A\00"
@TCSANOW = global i32 0
@.str.3 = [28 x i8] c"Can't set port attributes.\0A\00"
define void @initSerialPort(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = bitcast %struct.termios* %4 to i8*
%6 = call i64 @tcgetattr(i32 %0, %struct.termios* %4)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = call i64 @cfsetispeed(%struct.termios* %4, i32 %1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = call i64 @cfsetospeed(%struct.termios* %4, i32 %1)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %19
%27 = call i32 @makeraw(%struct.termios* %4, i32 %2)
%28 = load i32, i32* @TCSANOW
%29 = call i64 @tcsetattr(i32 %0, i32 %28, %struct.termios* %4)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %26
ret void
}