#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*/ TCSAFLUSH;
int /*<<< orphan*/ cfmakeraw(struct termios *);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int tty_reset(int fd) {
  struct termios options;
  if (tcgetattr(fd, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  cfmakeraw(&options);
  if (tcsetattr(fd, TCSAFLUSH, &options) == -1) {
    do {
    } while (0);
    do {
    } while (0);
    return (0);
  }
  return (1);
}


x86 assembly (clang, -O0):
<tty_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1170 <tty_reset+0x40>
jmp    1155 <tty_reset+0x25>
jmp    115a <tty_reset+0x2a>
jmp    115f <tty_reset+0x2f>
jmp    1164 <tty_reset+0x34>
movl   $0x0,-0x4(%rbp)
jmp    11be <tty_reset+0x8e>
lea    -0x10(%rbp),%rdi
call   1030 <cfmakeraw@plt>
mov    -0x8(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    11b7 <tty_reset+0x87>
jmp    119c <tty_reset+0x6c>
jmp    11a1 <tty_reset+0x71>
jmp    11a6 <tty_reset+0x76>
jmp    11ab <tty_reset+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    11be <tty_reset+0x8e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_reset>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     116d <tty_reset+0x3d>
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <cfmakeraw@plt>
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
setne  %al
jmp    116f <tty_reset+0x3f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
define i32 @tty_reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %1
br label %9
9: ; preds = %8
br label %10
10: ; preds = %9
br label %11
11: ; preds = %10
br label %12
12: ; preds = %11
store i32 0, i32* %2
br label %25
13: ; preds = %1
%14 = call i32 @cfmakeraw(%struct.termios* %4)
%15 = load i32, i32* %3
%16 = load i32, i32* @TCSAFLUSH
%17 = call i32 @tcsetattr(i32 %15, i32 %16, %struct.termios* %4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %13
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
br label %22
22: ; preds = %21
br label %23
23: ; preds = %22
store i32 0, i32* %2
br label %25
24: ; preds = %13
store i32 1, i32* %2
br label %25
25: ; preds = %24, %23, %12
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
define i32 @tty_reset(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = call i32 @cfmakeraw(%struct.termios* %2)
%8 = load i32, i32* @TCSAFLUSH
%9 = call i32 @tcsetattr(i32 %0, i32 %8, %struct.termios* %2)
%10 = icmp ne i32 %9, -1
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %6, %1
%13 = phi i32 [ 0, %1 ], [ %11, %6 ]
ret i32 %13
}