#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ die_errno(char *, int);
scalar_t__ errno;
int tcgetattr(int, struct termios *);
void xtcgetattr(int fd, struct termios *attr) {
  int ret;
  do {
    ret = tcgetattr(fd, attr);
  } while (ret == -1 && errno == EINTR);
  if (ret < 0)
    die_errno("tcgetattr(%d)", fd);
}


x86 assembly (clang, -O0):
<xtcgetattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jne    1167 <xtcgetattr+0x47>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    112f <xtcgetattr+0xf>
cmpl   $0x0,-0x14(%rbp)
jge    118b <xtcgetattr+0x6b>
mov    -0x4(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1030 <die_errno@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xtcgetattr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ead(%rip),%r14
mov    0x2e9e(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1157 <xtcgetattr+0x37>
mov    (%r15),%rcx
cmp    %rcx,(%r14)
je     1140 <xtcgetattr+0x20>
test   %eax,%eax
js     1166 <xtcgetattr+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe93(%rip),%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <die_errno@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [14 x i8] c"tcgetattr(%d)\00"
define void @xtcgetattr(i32 %0, %struct.termios* %1) {
%3 = alloca i32
%4 = alloca %struct.termios*
%5 = alloca i32
store i32 %0, i32* %3
store %struct.termios* %1, %struct.termios** %4
br label %6
6: ; preds = %17, %2
%7 = load i32, i32* %3
%8 = load %struct.termios*, %struct.termios** %4
%9 = call i32 @tcgetattr(i32 %7, %struct.termios* %8)
store i32 %9, i32* %5
br label %10
10: ; preds = %6
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ false, %10 ], [ %16, %13 ]
br i1 %18, label %6, label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i32, i32* %3
%24 = call i32 @die_errno(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
@.str = [14 x i8] c"tcgetattr(%d)\00"
define void @xtcgetattr(i32 %0, %struct.termios* %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 @tcgetattr(i32 %0, %struct.termios* %1)
%5 = icmp eq i32 %4, -1
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINTR
%8 = icmp eq i64 %6, %7
%9 = select i1 %5, i1 %8, i1 false
br i1 %9, label %3, label %10
10: ; preds = %3
%11 = icmp slt i32 %4, 0
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @die_errno(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %14
14: ; preds = %12, %10
ret void
}