#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 *c_cc;
  int c_iflag;
  int c_lflag;
  int /*<<< orphan*/ c_cflag;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int BRKINT;
int /*<<< orphan*/ CLOCAL;
int /*<<< orphan*/ CS8;
int ECHO;
int ECHOE;
int ECHOK;
int ECHOKE;
int ECHONL;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int IGNPAR;
int INLCR;
int INPCK;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int /*<<< orphan*/ PARENB;
int PARMRK;
int /*<<< orphan*/ TCSAFLUSH;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_raw_tty_mode(int fd) {
  struct termios ttymodes;
  if (tcgetattr(fd, &ttymodes) < 0) {
    perror("tcgetattr");
    exit(1);
  }
  ttymodes.c_cc[VMIN] = 1;
  ttymodes.c_cc[VTIME] = 0;
  ttymodes.c_iflag &= ~(ICRNL | INLCR | IGNCR | ISTRIP | IXON | BRKINT |
                        IGNPAR | PARMRK | IGNBRK | INPCK);
  ttymodes.c_lflag &=
      ~(ICANON | ECHO | ECHOE | ECHOK | ECHOKE | ECHONL | ISIG | IEXTEN);
  ttymodes.c_cflag |= CS8;
  ttymodes.c_cflag &= ~PARENB;
  ttymodes.c_oflag &= ~OPOST;
  ttymodes.c_cflag |= CLOCAL;
  if (tcsetattr(fd, TCSAFLUSH, &ttymodes) < 0) {
    perror("tcsetattr");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_raw_tty_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1030 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1177 <set_raw_tty_mode+0x37>
lea    0xe98(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rax
mov    0x2dfe(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    0x2da1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    0x2e27(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0e(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8d(%rip),%rcx
or     (%rcx),%eax
mov    0x2dec(%rip),%rcx
or     (%rcx),%eax
mov    0x2dbb(%rip),%rcx
or     (%rcx),%eax
mov    0x2d52(%rip),%rcx
or     (%rcx),%eax
mov    0x2e09(%rip),%rcx
or     (%rcx),%eax
mov    0x2d50(%rip),%rcx
or     (%rcx),%eax
mov    0x2d67(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d1d(%rip),%rax
mov    (%rax),%eax
mov    0x2d94(%rip),%rcx
or     (%rcx),%eax
mov    0x2d83(%rip),%rcx
or     (%rcx),%eax
mov    0x2d32(%rip),%rcx
or     (%rcx),%eax
mov    0x2d39(%rip),%rcx
or     (%rcx),%eax
mov    0x2d10(%rip),%rcx
or     (%rcx),%eax
mov    0x2d57(%rip),%rcx
or     (%rcx),%eax
mov    0x2d2e(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d2c(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2c89(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <tcsetattr@plt>
cmp    $0x0,%rax
jge    12cc <set_raw_tty_mode+0x18c>
lea    0xd4d(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_raw_tty_mode>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1030 <tcgetattr@plt>
test   %rax,%rax
js     1285 <set_raw_tty_mode+0x145>
mov    0x8(%rsp),%rax
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2dc1(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e58(%rip),%rax
mov    0x2e49(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e2e(%rip),%rax
or     (%rax),%ecx
mov    0x2dad(%rip),%rax
or     (%rax),%ecx
mov    0x2e0c(%rip),%rax
or     (%rax),%ecx
mov    0x2ddb(%rip),%rax
or     (%rax),%ecx
mov    0x2d72(%rip),%rax
or     (%rax),%ecx
mov    0x2e29(%rip),%rax
or     (%rax),%ecx
mov    0x2d70(%rip),%rax
or     (%rax),%ecx
mov    0x2d87(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x10(%rsp)
mov    0x2d40(%rip),%rax
mov    0x2db9(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2da6(%rip),%rax
or     (%rax),%ecx
mov    0x2d55(%rip),%rax
or     (%rax),%ecx
mov    0x2d5c(%rip),%rax
or     (%rax),%ecx
mov    0x2d33(%rip),%rax
or     (%rax),%ecx
mov    0x2d7a(%rip),%rax
or     (%rax),%ecx
mov    0x2d51(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x14(%rsp)
mov    0x2d52(%rip),%rax
mov    0x18(%rsp),%ecx
or     (%rax),%ecx
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x1c(%rsp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %ecx,%eax
mov    0x2cb9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d64(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <tcsetattr@plt>
test   %rax,%rax
js     128e <set_raw_tty_mode+0x14e>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xd74(%rip),%rdi
jmp    1295 <set_raw_tty_mode+0x155>
lea    0xd75(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32, i32, i32 }
@.str = [10 x i8] c"tcgetattr\00"
@VMIN = global i64 0
@VTIME = global i64 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@BRKINT = global i32 0
@IGNPAR = global i32 0
@PARMRK = global i32 0
@IGNBRK = global i32 0
@INPCK = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHOKE = global i32 0
@ECHONL = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@OPOST = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define void @set_raw_tty_mode(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%12 = load i32*, i32** %11
%13 = load i64, i64* @VMIN
%14 = getelementptr inbounds i32, i32* %12, i64 %13
store i32 1, i32* %14
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%16 = load i32*, i32** %15
%17 = load i64, i64* @VTIME
%18 = getelementptr inbounds i32, i32* %16, i64 %17
store i32 0, i32* %18
%19 = load i32, i32* @ICRNL
%20 = load i32, i32* @INLCR
%21 = or i32 %19, %20
%22 = load i32, i32* @IGNCR
%23 = or i32 %21, %22
%24 = load i32, i32* @ISTRIP
%25 = or i32 %23, %24
%26 = load i32, i32* @IXON
%27 = or i32 %25, %26
%28 = load i32, i32* @BRKINT
%29 = or i32 %27, %28
%30 = load i32, i32* @IGNPAR
%31 = or i32 %29, %30
%32 = load i32, i32* @PARMRK
%33 = or i32 %31, %32
%34 = load i32, i32* @IGNBRK
%35 = or i32 %33, %34
%36 = load i32, i32* @INPCK
%37 = or i32 %35, %36
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = load i32, i32* @ICANON
%43 = load i32, i32* @ECHO
%44 = or i32 %42, %43
%45 = load i32, i32* @ECHOE
%46 = or i32 %44, %45
%47 = load i32, i32* @ECHOK
%48 = or i32 %46, %47
%49 = load i32, i32* @ECHOKE
%50 = or i32 %48, %49
%51 = load i32, i32* @ECHONL
%52 = or i32 %50, %51
%53 = load i32, i32* @ISIG
%54 = or i32 %52, %53
%55 = load i32, i32* @IEXTEN
%56 = or i32 %54, %55
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @CS8
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%63 = load i32, i32* %62
%64 = or i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @PARENB
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @OPOST
%71 = xor i32 %70, -1
%72 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%73 = load i32, i32* %72
%74 = and i32 %73, %71
store i32 %74, i32* %72
%75 = load i32, i32* @CLOCAL
%76 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%77 = load i32, i32* %76
%78 = or i32 %77, %75
store i32 %78, i32* %76
%79 = load i32, i32* %2
%80 = load i32, i32* @TCSAFLUSH
%81 = call i64 @tcsetattr(i32 %79, i32 %80, %struct.termios* %3)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %10
%84 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %10
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32, i32, i32 }
@.str = [10 x i8] c"tcgetattr\00"
@VMIN = global i64 0
@VTIME = global i64 0
@ICRNL = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ISTRIP = global i32 0
@IXON = global i32 0
@BRKINT = global i32 0
@IGNPAR = global i32 0
@PARMRK = global i32 0
@IGNBRK = global i32 0
@INPCK = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ECHOK = global i32 0
@ECHOKE = global i32 0
@ECHONL = global i32 0
@ISIG = global i32 0
@IEXTEN = global i32 0
@CS8 = global i32 0
@PARENB = global i32 0
@OPOST = global i32 0
@CLOCAL = global i32 0
@TCSAFLUSH = global i32 0
@.str.1 = [10 x i8] c"tcsetattr\00"
define void @set_raw_tty_mode(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i64, i64* @VMIN
%13 = getelementptr inbounds i32, i32* %11, i64 %12
store i32 1, i32* %13
%14 = load i64, i64* @VTIME
%15 = getelementptr inbounds i32, i32* %11, i64 %14
store i32 0, i32* %15
%16 = load i32, i32* @ICRNL
%17 = load i32, i32* @INLCR
%18 = or i32 %17, %16
%19 = load i32, i32* @IGNCR
%20 = or i32 %18, %19
%21 = load i32, i32* @ISTRIP
%22 = or i32 %20, %21
%23 = load i32, i32* @IXON
%24 = or i32 %22, %23
%25 = load i32, i32* @BRKINT
%26 = or i32 %24, %25
%27 = load i32, i32* @IGNPAR
%28 = or i32 %26, %27
%29 = load i32, i32* @PARMRK
%30 = or i32 %28, %29
%31 = load i32, i32* @IGNBRK
%32 = or i32 %30, %31
%33 = load i32, i32* @INPCK
%34 = or i32 %32, %33
%35 = xor i32 %34, -1
%36 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%37 = load i32, i32* %36
%38 = and i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* @ICANON
%40 = load i32, i32* @ECHO
%41 = or i32 %40, %39
%42 = load i32, i32* @ECHOE
%43 = or i32 %41, %42
%44 = load i32, i32* @ECHOK
%45 = or i32 %43, %44
%46 = load i32, i32* @ECHOKE
%47 = or i32 %45, %46
%48 = load i32, i32* @ECHONL
%49 = or i32 %47, %48
%50 = load i32, i32* @ISIG
%51 = or i32 %49, %50
%52 = load i32, i32* @IEXTEN
%53 = or i32 %51, %52
%54 = xor i32 %53, -1
%55 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%56 = load i32, i32* %55
%57 = and i32 %56, %54
store i32 %57, i32* %55
%58 = load i32, i32* @CS8
%59 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%60 = load i32, i32* %59
%61 = or i32 %60, %58
%62 = load i32, i32* @PARENB
%63 = xor i32 %62, -1
%64 = and i32 %61, %63
%65 = load i32, i32* @OPOST
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = load i32, i32* @CLOCAL
%71 = or i32 %70, %64
store i32 %71, i32* %59
%72 = load i32, i32* @TCSAFLUSH
%73 = call i64 @tcsetattr(i32 %0, i32 %72, %struct.termios* %2)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %9
%76 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %9
ret void
}