#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 */
struct termios {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EBADF;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ ENOSYS;
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int __tcgetattr(int fd, struct termios *termios_p) {
  if (fd < 0) {
    __set_errno(EBADF);
    return -1;
  }
  if (termios_p == NULL) {
    __set_errno(EINVAL);
    return -1;
  }
  __set_errno(ENOSYS);
  return -1;
}


x86 assembly (clang, -O0):
<__tcgetattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1143 <__tcgetattr+0x33>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <__tcgetattr+0x6d>
cmpq   $0x0,-0x10(%rbp)
jne    1168 <__tcgetattr+0x58>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117d <__tcgetattr+0x6d>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__tcgetattr>:
push   %rax
test   %rsi,%rsi
jne    1123 <__tcgetattr+0x13>
mov    0x2ebb(%rip),%rax
test   %edi,%edi
js     112e <__tcgetattr+0x1e>
jmp    1135 <__tcgetattr+0x25>
mov    0x2ebe(%rip),%rax
test   %edi,%edi
jns    1135 <__tcgetattr+0x25>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@EBADF = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i32 @__tcgetattr(i32 %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios*
store i32 %0, i32* %4
store %struct.termios* %1, %struct.termios** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @EBADF
%10 = call i32 @__set_errno(i32 %9)
store i32 -1, i32* %3
br label %20
11: ; preds = %2
%12 = load %struct.termios*, %struct.termios** %5
%13 = icmp eq %struct.termios* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* @EINVAL
%16 = call i32 @__set_errno(i32 %15)
store i32 -1, i32* %3
br label %20
17: ; preds = %11
%18 = load i32, i32* @ENOSYS
%19 = call i32 @__set_errno(i32 %18)
store i32 -1, i32* %3
br label %20
20: ; preds = %17, %14, %8
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@EBADF = global i32 0
@EINVAL = global i32 0
@ENOSYS = global i32 0
define i32 @__tcgetattr(i32 %0, %struct.termios* readnone %1) {
%3 = icmp slt i32 %0, 0
%4 = icmp eq %struct.termios* %1, null
%5 = load i32, i32* @EBADF
%6 = load i32, i32* @EINVAL
%7 = load i32, i32* @ENOSYS
%8 = select i1 %4, i32 %6, i32 %7
%9 = select i1 %3, i32 %5, i32 %8
%10 = tail call i32 @__set_errno(i32 %9)
ret i32 -1
}