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

/* Variables and functions */
int BRKINT;
int /*<<< orphan*/ CS8;
int /*<<< orphan*/ CSIZE;
int ECHO;
int ICANON;
int ICRNL;
int IEXTEN;
int IGNBRK;
int IGNCR;
int IGNPAR;
int INLCR;
int INPCK;
int ISIG;
int ISTRIP;
int IXOFF;
int IXON;
int OCRNL;
int OFILL;
int ONLRET;
int ONOCR;
int OPOST;
int PARMRK;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ vt_mode_get(struct termios *);
int /*<<< orphan*/ vt_mode_set(struct termios *);
void vt_mode_set_toraw(struct termios *mode_original_ptr) {
  struct termios attr;
  vt_mode_get(&attr);
  if (mode_original_ptr != NULL) {
    (*mode_original_ptr) = attr;
  }
  attr.c_iflag &= ~(IGNBRK | BRKINT);
  attr.c_iflag |= PARMRK;
  attr.c_iflag |= IGNPAR;
  attr.c_iflag &= ~(INPCK);
  attr.c_iflag &= ~(ISTRIP);
  attr.c_iflag &= ~(INLCR | ICRNL);
  attr.c_iflag &= ~(IGNCR);
  attr.c_iflag &= ~(IXON | IXOFF);
  attr.c_oflag &= ~(OPOST);
  attr.c_oflag &= ~(OCRNL);
  attr.c_oflag &= ~(ONOCR | ONLRET);
  attr.c_oflag &= ~(OFILL);
  attr.c_cflag &= ~(CSIZE);
  attr.c_cflag |= CS8;
  attr.c_lflag &= ~(ISIG);
  attr.c_lflag &= ~(ICANON | IEXTEN);
  attr.c_lflag &= ~(ECHO);
  attr.c_cc[VMIN] = 1;
  attr.c_cc[VTIME] = 0;
  vt_mode_set(&attr);
}


x86 assembly (clang, -O0):
<vt_mode_set_toraw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <vt_mode_get@plt>
cmpq   $0x0,-0x8(%rbp)
je     1163 <vt_mode_set_toraw+0x43>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rcx
mov    %rcx,0x10(%rax)
mov    -0x10(%rbp),%rcx
mov    %rcx,0x18(%rax)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    0x2e1d(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da4(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    0x2e08(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    0x2dcb(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    0x2cf4(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2d17(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    0x2cd4(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cf2(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cbc(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2c67(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
lea    -0x28(%rbp),%rdi
call   1030 <vt_mode_set@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vt_mode_set_toraw>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1040 <vt_mode_get@plt>
test   %rbx,%rbx
je     1145 <vt_mode_set_toraw+0x25>
movups (%rsp),%xmm0
movups 0x10(%rsp),%xmm1
movups %xmm1,0x10(%rbx)
movups %xmm0,(%rbx)
mov    0x2dfc(%rip),%rcx
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    0x2e85(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcc(%rip),%rcx
or     (%rcx),%eax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2dd2(%rip),%rdx
or     (%rdx),%ecx
mov    0x2e49(%rip),%rdx
mov    0x2e4a(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
or     %ecx,%esi
mov    0x2e1d(%rip),%rcx
or     (%rcx),%esi
mov    0x2e04(%rip),%rcx
mov    0x2e1d(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %esi,%edx
not    %edx
and    %eax,%edx
mov    %edx,(%rsp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    0x2e28(%rip),%rcx
or     (%rcx),%eax
mov    0x2def(%rip),%rcx
mov    0x2d58(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
or     %eax,%edx
mov    0x2d73(%rip),%rax
or     (%rax),%edx
not    %edx
and    %edx,0x4(%rsp)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
not    %eax
and    0x18(%rsp),%eax
mov    0x2d85(%rip),%rcx
or     (%rcx),%eax
mov    0x2d8c(%rip),%rcx
mov    0x2d15(%rip),%rdx
mov    0x2d56(%rip),%rsi
mov    (%rsi),%esi
or     (%rdx),%esi
or     (%rcx),%esi
mov    %eax,0x18(%rsp)
mov    0x2d75(%rip),%rax
or     (%rax),%esi
not    %esi
and    %esi,0x8(%rsp)
mov    0x10(%rsp),%rax
mov    0x2d41(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2cf0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    %rsp,%rdi
call   1030 <vt_mode_set@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@IGNPAR = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@ICRNL = global i32 0
@IGNCR = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@OPOST = global i32 0
@OCRNL = global i32 0
@ONOCR = global i32 0
@ONLRET = global i32 0
@OFILL = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
define void @vt_mode_set_toraw(%struct.termios* %0) {
%2 = alloca %struct.termios*
%3 = alloca %struct.termios
store %struct.termios* %0, %struct.termios** %2
%4 = call i32 @vt_mode_get(%struct.termios* %3)
%5 = load %struct.termios*, %struct.termios** %2
%6 = icmp ne %struct.termios* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load %struct.termios*, %struct.termios** %2
%9 = bitcast %struct.termios* %8 to i8*
%10 = bitcast %struct.termios* %3 to i8*
br label %11
11: ; preds = %7, %1
%12 = load i32, i32* @IGNBRK
%13 = load i32, i32* @BRKINT
%14 = or i32 %12, %13
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @PARMRK
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%21 = load i32, i32* %20
%22 = or i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @IGNPAR
%24 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %23
store i32 %26, i32* %24
%27 = load i32, i32* @INPCK
%28 = xor i32 %27, -1
%29 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%30 = load i32, i32* %29
%31 = and i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* @ISTRIP
%33 = xor i32 %32, -1
%34 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%35 = load i32, i32* %34
%36 = and i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* @INLCR
%38 = load i32, i32* @ICRNL
%39 = or i32 %37, %38
%40 = xor i32 %39, -1
%41 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%42 = load i32, i32* %41
%43 = and i32 %42, %40
store i32 %43, i32* %41
%44 = load i32, i32* @IGNCR
%45 = xor i32 %44, -1
%46 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%47 = load i32, i32* %46
%48 = and i32 %47, %45
store i32 %48, i32* %46
%49 = load i32, i32* @IXON
%50 = load i32, i32* @IXOFF
%51 = or i32 %49, %50
%52 = xor i32 %51, -1
%53 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%54 = load i32, i32* %53
%55 = and i32 %54, %52
store i32 %55, i32* %53
%56 = load i32, i32* @OPOST
%57 = xor i32 %56, -1
%58 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%59 = load i32, i32* %58
%60 = and i32 %59, %57
store i32 %60, i32* %58
%61 = load i32, i32* @OCRNL
%62 = xor i32 %61, -1
%63 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%64 = load i32, i32* %63
%65 = and i32 %64, %62
store i32 %65, i32* %63
%66 = load i32, i32* @ONOCR
%67 = load i32, i32* @ONLRET
%68 = or i32 %66, %67
%69 = xor i32 %68, -1
%70 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%71 = load i32, i32* %70
%72 = and i32 %71, %69
store i32 %72, i32* %70
%73 = load i32, i32* @OFILL
%74 = xor i32 %73, -1
%75 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%76 = load i32, i32* %75
%77 = and i32 %76, %74
store i32 %77, i32* %75
%78 = load i32, i32* @CSIZE
%79 = xor i32 %78, -1
%80 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%81 = load i32, i32* %80
%82 = and i32 %81, %79
store i32 %82, i32* %80
%83 = load i32, i32* @CS8
%84 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%85 = load i32, i32* %84
%86 = or i32 %85, %83
store i32 %86, i32* %84
%87 = load i32, i32* @ISIG
%88 = xor i32 %87, -1
%89 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%90 = load i32, i32* %89
%91 = and i32 %90, %88
store i32 %91, i32* %89
%92 = load i32, i32* @ICANON
%93 = load i32, i32* @IEXTEN
%94 = or i32 %92, %93
%95 = xor i32 %94, -1
%96 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%97 = load i32, i32* %96
%98 = and i32 %97, %95
store i32 %98, i32* %96
%99 = load i32, i32* @ECHO
%100 = xor i32 %99, -1
%101 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%102 = load i32, i32* %101
%103 = and i32 %102, %100
store i32 %103, i32* %101
%104 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%105 = load i32*, i32** %104
%106 = load i64, i64* @VMIN
%107 = getelementptr inbounds i32, i32* %105, i64 %106
store i32 1, i32* %107
%108 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%109 = load i32*, i32** %108
%110 = load i64, i64* @VTIME
%111 = getelementptr inbounds i32, i32* %109, i64 %110
store i32 0, i32* %111
%112 = call i32 @vt_mode_set(%struct.termios* %3)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@IGNPAR = global i32 0
@INPCK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@ICRNL = global i32 0
@IGNCR = global i32 0
@IXON = global i32 0
@IXOFF = global i32 0
@OPOST = global i32 0
@OCRNL = global i32 0
@ONOCR = global i32 0
@ONLRET = global i32 0
@OFILL = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ISIG = global i32 0
@ICANON = global i32 0
@IEXTEN = global i32 0
@ECHO = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
define void @vt_mode_set_toraw(%struct.termios* writeonly %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i32 @vt_mode_get(%struct.termios* %2)
%5 = icmp eq %struct.termios* %0, null
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = bitcast %struct.termios* %0 to i8*
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* @IGNBRK
%10 = load i32, i32* @BRKINT
%11 = or i32 %10, %9
%12 = xor i32 %11, -1
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%14 = load i32, i32* %13
%15 = and i32 %14, %12
%16 = load i32, i32* @PARMRK
%17 = or i32 %16, %15
%18 = load i32, i32* @IGNPAR
%19 = or i32 %18, %17
%20 = load i32, i32* @INPCK
%21 = load i32, i32* @ISTRIP
%22 = or i32 %20, %21
%23 = load i32, i32* @INLCR
%24 = load i32, i32* @ICRNL
%25 = or i32 %24, %23
%26 = or i32 %22, %25
%27 = load i32, i32* @IGNCR
%28 = or i32 %26, %27
%29 = load i32, i32* @IXON
%30 = load i32, i32* @IXOFF
%31 = or i32 %30, %29
%32 = or i32 %28, %31
%33 = xor i32 %32, -1
%34 = and i32 %19, %33
store i32 %34, i32* %13
%35 = load i32, i32* @OPOST
%36 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%37 = load i32, i32* %36
%38 = load i32, i32* @OCRNL
%39 = or i32 %35, %38
%40 = load i32, i32* @ONOCR
%41 = load i32, i32* @ONLRET
%42 = or i32 %41, %40
%43 = or i32 %39, %42
%44 = load i32, i32* @OFILL
%45 = or i32 %43, %44
%46 = xor i32 %45, -1
%47 = and i32 %37, %46
store i32 %47, i32* %36
%48 = load i32, i32* @CSIZE
%49 = xor i32 %48, -1
%50 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%51 = load i32, i32* %50
%52 = and i32 %51, %49
%53 = load i32, i32* @CS8
%54 = or i32 %53, %52
store i32 %54, i32* %50
%55 = load i32, i32* @ISIG
%56 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%57 = load i32, i32* %56
%58 = load i32, i32* @ICANON
%59 = load i32, i32* @IEXTEN
%60 = or i32 %59, %58
%61 = or i32 %55, %60
%62 = load i32, i32* @ECHO
%63 = or i32 %61, %62
%64 = xor i32 %63, -1
%65 = and i32 %57, %64
store i32 %65, i32* %56
%66 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%67 = load i32*, i32** %66
%68 = load i64, i64* @VMIN
%69 = getelementptr inbounds i32, i32* %67, i64 %68
store i32 1, i32* %69
%70 = load i64, i64* @VTIME
%71 = getelementptr inbounds i32, i32* %67, i64 %70
store i32 0, i32* %71
%72 = call i32 @vt_mode_set(%struct.termios* %2)
ret void
}