#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*/ B1000000;
int /*<<< orphan*/ EXIT_FAILURE;
int O_NOCTTY;
int O_RDWR;
int O_SYNC;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, char *, char *, char *);
int /*<<< orphan*/ set_avr_attribs(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ set_avr_blocking(int, int /*<<< orphan*/);
char *strerror(int /*<<< orphan*/);
int avr_open(char *portname) {
  int fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
  if (fd < 0) {
    printf("error %s opening %s: %s", strerror(errno), portname,
           strerror(errno));
    exit(EXIT_FAILURE);
  }
  set_avr_attribs(fd, B1000000, 0);
  set_avr_blocking(fd, 0);
  return fd;
}


x86 assembly (clang, -O0):
<avr_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
or     (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ea <avr_open+0x8a>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    %rax,%rcx
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <set_avr_attribs@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <set_avr_blocking@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<avr_open>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e7d(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rdi,%rbx
mov    0x2e60(%rip),%rax
or     (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     11af <avr_open+0x4f>
mov    %eax,%ebp
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1080 <set_avr_attribs@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <set_avr_blocking@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e0a(%rip),%r14
mov    (%r14),%edi
call   1070 <strerror@plt>
mov    %rax,%rbp
mov    (%r14),%edi
call   1070 <strerror@plt>
lea    0xe30(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1030 <printf@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str = [24 x i8] c"error %s opening %s: %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@B1000000 = global i32 0
define i32 @avr_open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_SYNC
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %4, i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %1
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = load i8*, i8** %2
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %1
%23 = load i32, i32* %3
%24 = load i32, i32* @B1000000
%25 = call i32 @set_avr_attribs(i32 %23, i32 %24, i32 0)
%26 = load i32, i32* %3
%27 = call i32 @set_avr_blocking(i32 %26, i32 0)
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str = [24 x i8] c"error %s opening %s: %s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@B1000000 = global i32 0
define i32 @avr_open(i8* %0) {
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = load i32, i32* @O_SYNC
%6 = or i32 %4, %5
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %0, i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* @B1000000
%19 = tail call i32 @set_avr_attribs(i32 %7, i32 %18, i32 0)
%20 = tail call i32 @set_avr_blocking(i32 %7, i32 0)
ret i32 %7
}