#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 */

/* Variables and functions */
int /*<<< orphan*/ F_SETFL;
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ uarthandler_config(int);
int uarthandler_getBaud(int);
int uarthandler_init(void) {
  int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
  if (fd == -1) {
    perror("open_port: Unable to open /dev/ttyS0 - ");
    return 1;
  } else {
    fcntl(fd, F_SETFL, 0);
    printf("Serial connection established on /dev/ttyS0\n");
  }
  printf("Default baud\t= %d\n", uarthandler_getBaud(fd));
  uarthandler_config(fd);
  printf("Conifgured baud\t= %d\n", uarthandler_getBaud(fd));
  return fd;
}


x86 assembly (clang, -O0):
<uarthandler_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
mov    0x2e47(%rip),%rax
or     (%rax),%esi
lea    0xe76(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11b4 <uarthandler_init+0x54>
lea    0xe68(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <uarthandler_init+0xb3>
mov    -0x8(%rbp),%edi
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <uarthandler_getBaud@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <uarthandler_config@plt>
mov    -0x8(%rbp),%edi
call   1060 <uarthandler_getBaud@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uarthandler_init>:
push   %rbx
mov    0x2e70(%rip),%rax
mov    0x2e59(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3e(%rip),%rax
or     (%rax),%esi
lea    0xedf(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11f6 <uarthandler_init+0x86>
mov    %eax,%ebx
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1040 <fcntl@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <uarthandler_getBaud@plt>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <uarthandler_config@plt>
mov    %ebx,%edi
call   1070 <uarthandler_getBaud@plt>
lea    0xe52(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
jmp    11f2 <uarthandler_init+0x82>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [40 x i8] c"open_port: Unable to open /dev/ttyS0 - \00"
@F_SETFL = global i32 0
@.str.2 = [45 x i8] c"Serial connection established on /dev/ttyS0\0A\00"
@.str.3 = [19 x i8] c"Default baud\09= %d\0A\00"
@.str.4 = [22 x i8] c"Conifgured baud\09= %d\0A\00"
define i32 @uarthandler_init() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %3, %4
%6 = load i32, i32* @O_NDELAY
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %28
13: ; preds = %0
%14 = load i32, i32* %2
%15 = load i32, i32* @F_SETFL
%16 = call i32 @fcntl(i32 %14, i32 %15, i32 0)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %13
%19 = load i32, i32* %2
%20 = call i32 @uarthandler_getBaud(i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @uarthandler_config(i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @uarthandler_getBaud(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %2
store i32 %27, i32* %1
br label %28
28: ; preds = %18, %11
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str.1 = [40 x i8] c"open_port: Unable to open /dev/ttyS0 - \00"
@F_SETFL = global i32 0
@.str.3 = [19 x i8] c"Default baud\09= %d\0A\00"
@.str.4 = [22 x i8] c"Conifgured baud\09= %d\0A\00"
@str = [44 x i8] c"Serial connection established on /dev/ttyS0\00"
define i32 @uarthandler_init() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = load i32, i32* @O_NDELAY
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %19
10: ; preds = %0
%11 = load i32, i32* @F_SETFL
%12 = tail call i32 @fcntl(i32 %6, i32 %11, i32 0)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @uarthandler_getBaud(i32 %6)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = tail call i32 @uarthandler_config(i32 %6)
%17 = tail call i32 @uarthandler_getBaud(i32 %6)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %10, %8
%20 = phi i32 [ 1, %8 ], [ %6, %10 ]
ret i32 %20
}