#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*/ B115200;
int O_NOCTTY;
int O_RDWR;
int O_SYNC;
int errno;
int open(char *, int);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int /*<<< orphan*/ set_blocking(int, int /*<<< orphan*/);
int /*<<< orphan*/ set_interface_attribs(int, int /*<<< orphan*/,
                                         int /*<<< orphan*/);
char *strerror(int);
int openSerial() {
  char *portname = "/dev/ttyMCC";
  int fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
  if (fd < 0) {
    printf("error %d opening %s: %s", errno, portname, strerror(errno));
    return 0;
  }
  set_interface_attribs(fd, B115200, 0);
  set_blocking(fd, 0);
  return fd;
}


x86 assembly (clang, -O0):
<openSerial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
mov    0x2e59(%rip),%rax
or     (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d8 <openSerial+0x88>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe45(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11fb <openSerial+0xab>
mov    -0x14(%rbp),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <set_interface_attribs@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <set_blocking@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openSerial>:
push   %rbx
mov    0x2e90(%rip),%rax
mov    0x2e71(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     119b <openSerial+0x4b>
mov    %eax,%ebx
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <set_interface_attribs@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <set_blocking@plt>
jmp    11c5 <openSerial+0x75>
mov    0x2e26(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe5a(%rip),%rdi
lea    0xe47(%rip),%rdx
mov    %ebx,%esi
mov    %rax,%rcx
call   1040 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/ttyMCC\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [24 x i8] c"error %d opening %s: %s\00"
@errno = global i32 0
@B115200 = global i32 0
define i32 @openSerial() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 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 %19
13: ; preds = %0
%14 = load i32, i32* @errno
%15 = load i8*, i8** %2
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %15, i8* %17)
store i32 0, i32* %1
br label %26
19: ; preds = %0
%20 = load i32, i32* %3
%21 = load i32, i32* @B115200
%22 = call i32 @set_interface_attribs(i32 %20, i32 %21, i32 0)
%23 = load i32, i32* %3
%24 = call i32 @set_blocking(i32 %23, i32 0)
%25 = load i32, i32* %3
store i32 %25, i32* %1
br label %26
26: ; preds = %19, %13
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/ttyMCC\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_SYNC = global i32 0
@.str.1 = [24 x i8] c"error %d opening %s: %s\00"
@errno = global i32 0
@B115200 = global i32 0
define i32 @openSerial() {
%1 = load i32, i32* @O_RDWR
%2 = load i32, i32* @O_NOCTTY
%3 = or i32 %2, %1
%4 = load i32, i32* @O_SYNC
%5 = or i32 %3, %4
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %16
12: ; preds = %0
%13 = load i32, i32* @B115200
%14 = tail call i32 @set_interface_attribs(i32 %6, i32 %13, i32 0)
%15 = tail call i32 @set_blocking(i32 %6, i32 0)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ 0, %8 ], [ %6, %12 ]
ret i32 %17
}