#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 O_NOCTTY;
int O_RDONLY;
int /*<<< orphan*/ errno;
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
int pi_tty_init(void) {
  int fd;
  fd = open("/dev/ttyAMA0", O_RDONLY | O_NOCTTY);
  if (fd < 0) {
    printf("failed to open UART port: %s\n", strerror(errno));
    return -5;
  }
  return 0;
}


x86 assembly (clang, -O0):
<pi_tty_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
mov    0x2e90(%rip),%rax
or     (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    118c <pi_tty_init+0x5c>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1193 <pi_tty_init+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pi_tty_init>:
push   %rax
mov    0x2eb0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb6(%rip),%rdi
call   1040 <open@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     1159 <pi_tty_init+0x29>
pop    %rcx
ret
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0xfffffffb,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [30 x i8] c"failed to open UART port: %s\0A\00"
@errno = global i32 0
define i32 @pi_tty_init() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDONLY
%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* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 -5, i32* %1
br label %14
13: ; preds = %0
store i32 0, i32* %1
br label %14
14: ; preds = %13, %9
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyAMA0\00"
@O_RDONLY = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [30 x i8] c"failed to open UART port: %s\0A\00"
@errno = global i32 0
define i32 @pi_tty_init() {
%1 = load i32, i32* @O_RDONLY
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %0, %6
%11 = phi i32 [ -5, %6 ], [ 0, %0 ]
ret i32 %11
}