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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int CLOCAL;
int CREAD;
int CRTSCTS;
int CS8;
int CSIZE;
int CSTOPB;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int initport(int fd) {
  struct termios options;
  tcgetattr(fd, &options);
  printf("Original serial port settings: \n");
  printf("Serial port configuration c_cflag = %x \n", options.c_cflag);
  printf("Serial port configuration c_iflag = %x \n", options.c_iflag);
  printf("Serial port configuration c_oflag = %x \n", options.c_oflag);
  printf("Serial port configuration c_lflag = %x \n", options.c_lflag);
  cfmakeraw(&options);
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~PARENB;
  options.c_cflag &= ~CSTOPB;
  options.c_cflag &= ~CSIZE;
  options.c_cflag |= CS8;
  options.c_cflag &= ~CRTSCTS;
  tcsetattr(fd, TCSANOW, &options);
  tcgetattr(fd, &options);
  printf("Flip-flop's serial port settings: \n");
  printf("Serial port configuration c_cflag = %x \n", options.c_cflag);
  printf("Serial port configuration c_iflag = %x \n", options.c_iflag);
  printf("Serial port configuration c_oflag = %x \n", options.c_oflag);
  printf("Serial port configuration c_lflag = %x \n", options.c_lflag);
  return 1;
}


x86 assembly (clang, -O0):
<initport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <tcgetattr@plt>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
call   1050 <cfmakeraw@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    0x2dca(%rip),%rcx
or     (%rcx),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d71(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1060 <tcgetattr@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initport>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
lea    0xf10(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe73(%rip),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe87(%rip),%r13
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
lea    0xe9b(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1060 <cfmakeraw@plt>
mov    0x2ddf(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d82(%rip),%rax
mov    0x2db3(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     0x8(%rsp),%ecx
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    0x2d6b(%rip),%rdx
or     (%rdx),%eax
mov    0x2d82(%rip),%rdx
or     (%rdx),%eax
not    %eax
and    %ecx,%eax
mov    0x2d7d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d54(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %eax,%ecx
mov    %ecx,0x8(%rsp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
lea    0xe42(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%esi
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@.str = [33 x i8] c"Original serial port settings: \0A\00"
@.str.1 = [41 x i8] c"Serial port configuration c_cflag = %x \0A\00"
@.str.2 = [41 x i8] c"Serial port configuration c_iflag = %x \0A\00"
@.str.3 = [41 x i8] c"Serial port configuration c_oflag = %x \0A\00"
@.str.4 = [41 x i8] c"Serial port configuration c_lflag = %x \0A\00"
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@.str.5 = [36 x i8] c"Flip-flop's serial port settings: \0A\00"
define i32 @initport(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%8 = load i32, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%11 = load i32, i32* %10
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%14 = load i32, i32* %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = call i32 @cfmakeraw(%struct.termios* %3)
%20 = load i32, i32* @B9600
%21 = call i32 @cfsetispeed(%struct.termios* %3, i32 %20)
%22 = load i32, i32* @B9600
%23 = call i32 @cfsetospeed(%struct.termios* %3, i32 %22)
%24 = load i32, i32* @CLOCAL
%25 = load i32, i32* @CREAD
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%28 = load i32, i32* %27
%29 = or i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @PARENB
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @CSTOPB
%36 = xor i32 %35, -1
%37 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%38 = load i32, i32* %37
%39 = and i32 %38, %36
store i32 %39, i32* %37
%40 = load i32, i32* @CSIZE
%41 = xor i32 %40, -1
%42 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%43 = load i32, i32* %42
%44 = and i32 %43, %41
store i32 %44, i32* %42
%45 = load i32, i32* @CS8
%46 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%47 = load i32, i32* %46
%48 = or i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @CRTSCTS
%50 = xor i32 %49, -1
%51 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%52 = load i32, i32* %51
%53 = and i32 %52, %50
store i32 %53, i32* %51
%54 = load i32, i32* %2
%55 = load i32, i32* @TCSANOW
%56 = call i32 @tcsetattr(i32 %54, i32 %55, %struct.termios* %3)
%57 = load i32, i32* %2
%58 = call i32 @tcgetattr(i32 %57, %struct.termios* %3)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%60 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %61)
%63 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%64 = load i32, i32* %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%67 = load i32, i32* %66
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%70 = load i32, i32* %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %70)
ret i32 1
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@.str.1 = [41 x i8] c"Serial port configuration c_cflag = %x \0A\00"
@.str.2 = [41 x i8] c"Serial port configuration c_iflag = %x \0A\00"
@.str.3 = [41 x i8] c"Serial port configuration c_oflag = %x \0A\00"
@.str.4 = [41 x i8] c"Serial port configuration c_lflag = %x \0A\00"
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@CRTSCTS = global i32 0
@TCSANOW = global i32 0
@str = [32 x i8] c"Original serial port settings: \00"
@str.6 = [35 x i8] c"Flip-flop's serial port settings: \00"
define i32 @initport(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%10 = load i32, i32* %9
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%13 = load i32, i32* %12
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%16 = load i32, i32* %15
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = call i32 @cfmakeraw(%struct.termios* %2)
%19 = load i32, i32* @B9600
%20 = call i32 @cfsetispeed(%struct.termios* %2, i32 %19)
%21 = load i32, i32* @B9600
%22 = call i32 @cfsetospeed(%struct.termios* %2, i32 %21)
%23 = load i32, i32* @CLOCAL
%24 = load i32, i32* @CREAD
%25 = or i32 %24, %23
%26 = load i32, i32* %6
%27 = or i32 %25, %26
%28 = load i32, i32* @PARENB
%29 = load i32, i32* @CSTOPB
%30 = or i32 %28, %29
%31 = load i32, i32* @CSIZE
%32 = or i32 %30, %31
%33 = xor i32 %32, -1
%34 = and i32 %27, %33
%35 = load i32, i32* @CS8
%36 = or i32 %35, %34
%37 = load i32, i32* @CRTSCTS
%38 = xor i32 %37, -1
%39 = and i32 %36, %38
store i32 %39, i32* %6
%40 = load i32, i32* @TCSANOW
%41 = call i32 @tcsetattr(i32 %0, i32 %40, %struct.termios* %2)
%42 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %9
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %12
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %48)
%50 = load i32, i32* %15
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %50)
ret i32 1
}