#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;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int B115200;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ TCSANOW;
int open(char *, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init_serial(char *device) {
  int serialfd;
  struct termios config;
  serialfd = open(device, O_RDWR | O_NONBLOCK);
  config.c_iflag = IGNPAR;
  config.c_oflag = 0;
  config.c_cflag = CS8 | CREAD | CLOCAL | B115200;
  config.c_lflag = 0;
  if (tcsetattr(serialfd, TCSANOW, &config) == 0)
    printf("Serial Port Opened\n");
  return serialfd;
}


x86 assembly (clang, -O0):
<init_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
or     (%rcx),%eax
mov    0x2e19(%rip),%rcx
or     (%rcx),%eax
mov    0x2e28(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jne    11c8 <init_serial+0x98>
lea    0xe3d(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_serial>:
push   %rbx
sub    $0x20,%rsp
mov    0x2eac(%rip),%rax
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,%ebx
mov    0x2e73(%rip),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e2c(%rip),%rax
or     (%rax),%ecx
mov    0x2e3b(%rip),%rax
or     (%rax),%ecx
mov    %ecx,(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x8(%rsp)
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
test   %rax,%rax
jne    11ae <init_serial+0x7e>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64, i64, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@IGNPAR = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@.str = [20 x i8] c"Serial Port Opened\0A\00"
define i32 @init_serial(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.termios
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = call i32 @open(i8* %5, i32 %8)
store i32 %9, i32* %3
%10 = load i32, i32* @IGNPAR
%11 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
store i32 %10, i32* %11
%12 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i64 0, i64* %12
%13 = load i32, i32* @CS8
%14 = load i32, i32* @CREAD
%15 = or i32 %13, %14
%16 = load i32, i32* @CLOCAL
%17 = or i32 %15, %16
%18 = load i32, i32* @B115200
%19 = or i32 %17, %18
%20 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
store i64 0, i64* %21
%22 = load i32, i32* %3
%23 = load i32, i32* @TCSANOW
%24 = call i64 @tcsetattr(i32 %22, i32 %23, %struct.termios* %4)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %1
%27 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %1
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.termios = type { i32, i64, i64, i32 }
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@IGNPAR = global i32 0
@CS8 = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
@B115200 = global i32 0
@TCSANOW = global i32 0
@str = [19 x i8] c"Serial Port Opened\00"
define i32 @init_serial(i8* nocapture %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = load i32, i32* @O_RDWR
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = load i32, i32* @IGNPAR
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
store i32 %8, i32* %9
%10 = load i32, i32* @CS8
%11 = load i32, i32* @CREAD
%12 = or i32 %11, %10
%13 = load i32, i32* @CLOCAL
%14 = or i32 %12, %13
%15 = load i32, i32* @B115200
%16 = or i32 %14, %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%19 = bitcast i64* %18 to <2 x i64>*
store <2 x i64> zeroinitializer, <2 x i64>* %19
%20 = load i32, i32* @TCSANOW
%21 = call i64 @tcsetattr(i32 %7, i32 %20, %struct.termios* %2)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %1
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %25
25: ; preds = %23, %1
ret i32 %7
}