#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 B9600;
int CLOCAL;
int CREAD;
int CS8;
int /*<<< orphan*/ IGNPAR;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int InitUart() {
  int uart0_filestream = -1;
  uart0_filestream = open("/dev/ttyAMA0", O_RDWR | O_NOCTTY);
  if (uart0_filestream == -1) {
    printf("Error - Unable to open UART.  Ensure it is not in use by another "
           "application\n");
  } else {
    struct termios options;
    tcgetattr(uart0_filestream, &options);
    options.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
    options.c_iflag = IGNPAR;
    options.c_oflag = 0;
    options.c_lflag = 0;
    tcflush(uart0_filestream, TCIFLUSH);
    tcsetattr(uart0_filestream, TCSANOW, &options);
  }
  return uart0_filestream;
}


x86 assembly (clang, -O0):
<InitUart>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e41(%rip),%rax
or     (%rax),%esi
lea    0xe88(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    119b <InitUart+0x4b>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
jmp    1210 <InitUart+0xc0>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    0x2e11(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd8(%rip),%rcx
or     (%rcx),%eax
mov    0x2e07(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
call   1030 <tcflush@plt>
mov    -0x4(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InitUart>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2e8a(%rip),%rax
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe90(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     11ed <InitUart+0x9d>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e46(%rip),%rax
mov    0x2e2f(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2df4(%rip),%rax
or     (%rax),%ecx
mov    0x2e23(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
jmp    11f9 <InitUart+0xa9>
lea    0xe19(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64, i64, i32 }
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [78 x i8] c"Error - Unable to open UART. Ensure it is not in use by another application\0A\00"
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @InitUart() {
%1 = alloca i32
%2 = alloca %struct.termios
store i32 -1, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.1, i64 0, i64 0))
br label %32
11: ; preds = %0
%12 = load i32, i32* %1
%13 = call i32 @tcgetattr(i32 %12, %struct.termios* %2)
%14 = load i32, i32* @B9600
%15 = load i32, i32* @CS8
%16 = or i32 %14, %15
%17 = load i32, i32* @CLOCAL
%18 = or i32 %16, %17
%19 = load i32, i32* @CREAD
%20 = or i32 %18, %19
%21 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* @IGNPAR
%23 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 3
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 2
store i64 0, i64* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
store i64 0, i64* %25
%26 = load i32, i32* %1
%27 = load i32, i32* @TCIFLUSH
%28 = call i32 @tcflush(i32 %26, i32 %27)
%29 = load i32, i32* %1
%30 = load i32, i32* @TCSANOW
%31 = call i32 @tcsetattr(i32 %29, i32 %30, %struct.termios* %2)
br label %32
32: ; preds = %11, %9
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
%struct.termios = type { i32, i64, i64, i32 }
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@IGNPAR = global i32 0
@TCIFLUSH = global i32 0
@TCSANOW = global i32 0
@str = [77 x i8] c"Error - Unable to open UART. Ensure it is not in use by another application\00"
define i32 @InitUart() {
%1 = alloca %struct.termios
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %28
9: ; preds = %0
%10 = bitcast %struct.termios* %1 to i8*
%11 = call i32 @tcgetattr(i32 %5, %struct.termios* %1)
%12 = load i32, i32* @B9600
%13 = load i32, i32* @CS8
%14 = or i32 %13, %12
%15 = load i32, i32* @CLOCAL
%16 = or i32 %14, %15
%17 = load i32, i32* @CREAD
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @IGNPAR
%21 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 3
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
%23 = bitcast i64* %22 to i8*
%24 = load i32, i32* @TCIFLUSH
%25 = call i32 @tcflush(i32 %5, i32 %24)
%26 = load i32, i32* @TCSANOW
%27 = call i32 @tcsetattr(i32 %5, i32 %26, %struct.termios* %1)
br label %28
28: ; preds = %9, %7
ret i32 %5
}