#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*/ InitTTY(int, int, int);
int O_NDELAY;
int O_NOCTTY;
int O_RDWR;
int open(char *, int);
int OpenTTY(char *devname, int LineSpeed, int Flags) {
  int tty;
  if (Flags & 2048)
    tty = open(devname, O_RDWR | O_NOCTTY | O_NDELAY);
  else
    tty = open(devname, O_RDWR | O_NOCTTY);
  if (tty < 0)
    return (-1);
  InitTTY(tty, LineSpeed, Flags);
  return (tty);
}


x86 assembly (clang, -O0):
<OpenTTY>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x800,%eax
cmp    $0x0,%eax
je     116f <OpenTTY+0x4f>
mov    -0x10(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    0x2e81(%rip),%rax
or     (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
call   1030 <open@plt>
mov    %eax,-0x1c(%rbp)
jmp    118d <OpenTTY+0x6d>
mov    -0x10(%rbp),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
mov    0x2e55(%rip),%rax
or     (%rax),%esi
call   1030 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11a3 <OpenTTY+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <OpenTTY+0x97>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1040 <InitTTY@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenTTY>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edx,%esi
shl    $0x14,%esi
sar    $0x1f,%esi
mov    0x2eb0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e86(%rip),%rax
and    (%rax),%esi
or     %ecx,%esi
call   1030 <open@plt>
test   %eax,%eax
js     1167 <OpenTTY+0x47>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <InitTTY@plt>
jmp    116c <OpenTTY+0x4c>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
define i32 @OpenTTY(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = and i32 %9, 2048
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_NOCTTY
%16 = or i32 %14, %15
%17 = load i32, i32* @O_NDELAY
%18 = or i32 %16, %17
%19 = call i32 @open(i8* %13, i32 %18)
store i32 %19, i32* %8
br label %26
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_NOCTTY
%24 = or i32 %22, %23
%25 = call i32 @open(i8* %21, i32 %24)
store i32 %25, i32* %8
br label %26
26: ; preds = %20, %12
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %4
br label %36
30: ; preds = %26
%31 = load i32, i32* %8
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = call i32 @InitTTY(i32 %31, i32 %32, i32 %33)
%35 = load i32, i32* %8
store i32 %35, i32* %4
br label %36
36: ; preds = %30, %29
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
define i32 @OpenTTY(i8* nocapture %0, i32 %1, i32 %2) {
%4 = and i32 %2, 2048
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* @O_RDWR
%7 = load i32, i32* @O_NOCTTY
%8 = or i32 %7, %6
%9 = load i32, i32* @O_NDELAY
%10 = select i1 %5, i32 0, i32 %9
%11 = or i32 %8, %10
%12 = tail call i32 @open(i8* %0, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = tail call i32 @InitTTY(i32 %12, i32 %1, i32 %2)
br label %16
16: ; preds = %3, %14
%17 = phi i32 [ %12, %14 ], [ -1, %3 ]
ret i32 %17
}