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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ IGNCR;
int /*<<< orphan*/ ISIG;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ do_something();
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int main(void) {
  struct termios save_term;
  struct termios temp_term;
  errno = 0;
  if (tcgetattr(fileno(stdin), &save_term) == -1) {
    perror("tcgetattr failure");
    exit(EXIT_FAILURE);
  } else {
    temp_term = save_term;
  }
  temp_term.c_iflag &= IGNCR;
  temp_term.c_lflag &= ~ICANON;
  temp_term.c_lflag &= ~ECHO;
  temp_term.c_lflag &= ~ISIG;
  temp_term.c_cc[VMIN] = 1;
  temp_term.c_cc[VTIME] = 0;
  errno = 0;
  if (tcsetattr(fileno(stdin), TCSANOW, &temp_term) == -1) {
    perror("tcsetattr(temp_term) failure");
    exit(EXIT_FAILURE);
  } else {
    do_something();
  }
  errno = 0;
  if (tcsetattr(fileno(stdin), TCSANOW, &save_term) == -1) {
    perror("tcsetattr(save_term) failure");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3a(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11b9 <main+0x59>
lea    0xe5a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2da7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x28(%rbp),%rax
mov    0x2d6a(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2d71(%rip),%rax
movq   $0x0,(%rax)
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    128b <main+0x12b>
lea    0xd9a(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1030 <do_something@plt>
mov    0x2d17(%rip),%rax
movq   $0x0,(%rax)
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    12e5 <main+0x185>
lea    0xd5d(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    0x2e40(%rip),%r14
movq   $0x0,(%r14)
mov    0x2e62(%rip),%rbx
mov    (%rbx),%edi
call   1040 <fileno@plt>
lea    0x10(%rsp),%rsi
mov    %eax,%edi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11a2 <main+0x42>
lea    0xe63(%rip),%rdi
jmp    125f <main+0xff>
movups 0x10(%rsp),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
and    %eax,0xc(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    0x2e08(%rip),%rcx
or     (%rcx),%eax
mov    0x2df7(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    %eax,0x8(%rsp)
mov    (%rsp),%rax
mov    0x2ddc(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2da3(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
movq   $0x0,(%r14)
mov    (%rbx),%edi
call   1040 <fileno@plt>
mov    0x2dc4(%rip),%r15
mov    (%r15),%esi
mov    %rsp,%rdx
mov    %eax,%edi
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    122f <main+0xcf>
lea    0xde5(%rip),%rdi
jmp    125f <main+0xff>
xor    %eax,%eax
call   1030 <do_something@plt>
movq   $0x0,(%r14)
mov    (%rbx),%edi
call   1040 <fileno@plt>
mov    (%r15),%esi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
call   1060 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    1272 <main+0x112>
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32 }
@errno = global i64 0
@stdin = global i32 0
@.str = [18 x i8] c"tcgetattr failure\00"
@EXIT_FAILURE = global i32 0
@IGNCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [29 x i8] c"tcsetattr(temp_term) failure\00"
@.str.2 = [29 x i8] c"tcsetattr(save_term) failure\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
store i32 0, i32* %1
store i64 0, i64* @errno
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %2)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = bitcast %struct.termios* %3 to i8*
%14 = bitcast %struct.termios* %2 to i8*
br label %15
15: ; preds = %12
%16 = load i32, i32* @IGNCR
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @ICANON
%21 = xor i32 %20, -1
%22 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%23 = load i32, i32* %22
%24 = and i32 %23, %21
store i32 %24, i32* %22
%25 = load i32, i32* @ECHO
%26 = xor i32 %25, -1
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%28 = load i32, i32* %27
%29 = and i32 %28, %26
store i32 %29, i32* %27
%30 = load i32, i32* @ISIG
%31 = xor i32 %30, -1
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%33 = load i32, i32* %32
%34 = and i32 %33, %31
store i32 %34, i32* %32
%35 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%36 = load i32*, i32** %35
%37 = load i64, i64* @VMIN
%38 = getelementptr inbounds i32, i32* %36, i64 %37
store i32 1, i32* %38
%39 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%40 = load i32*, i32** %39
%41 = load i64, i64* @VTIME
%42 = getelementptr inbounds i32, i32* %40, i64 %41
store i32 0, i32* %42
store i64 0, i64* @errno
%43 = load i32, i32* @stdin
%44 = call i32 @fileno(i32 %43)
%45 = load i32, i32* @TCSANOW
%46 = call i32 @tcsetattr(i32 %44, i32 %45, %struct.termios* %3)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %15
%49 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %15
%53 = call i32 (...) @do_something()
br label %54
54: ; preds = %52
store i64 0, i64* @errno
%55 = load i32, i32* @stdin
%56 = call i32 @fileno(i32 %55)
%57 = load i32, i32* @TCSANOW
%58 = call i32 @tcsetattr(i32 %56, i32 %57, %struct.termios* %2)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %54
%61 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %54
%65 = load i32, i32* @EXIT_SUCCESS
%66 = call i32 @exit(i32 %65)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32 }
@errno = global i64 0
@stdin = global i32 0
@.str = [18 x i8] c"tcgetattr failure\00"
@EXIT_FAILURE = global i32 0
@IGNCR = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ISIG = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [29 x i8] c"tcsetattr(temp_term) failure\00"
@.str.2 = [29 x i8] c"tcsetattr(save_term) failure\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
store i64 0, i64* @errno
%5 = load i32, i32* @stdin
%6 = tail call i32 @fileno(i32 %5)
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %1)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @IGNCR
%15 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%16 = load i32, i32* %15
%17 = and i32 %16, %14
store i32 %17, i32* %15
%18 = load i32, i32* @ICANON
%19 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%20 = load i32, i32* %19
%21 = load i32, i32* @ECHO
%22 = or i32 %18, %21
%23 = load i32, i32* @ISIG
%24 = or i32 %22, %23
%25 = xor i32 %24, -1
%26 = and i32 %20, %25
store i32 %26, i32* %19
%27 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%28 = load i32*, i32** %27
%29 = load i64, i64* @VMIN
%30 = getelementptr inbounds i32, i32* %28, i64 %29
store i32 1, i32* %30
%31 = load i64, i64* @VTIME
%32 = getelementptr inbounds i32, i32* %28, i64 %31
store i32 0, i32* %32
store i64 0, i64* @errno
%33 = load i32, i32* @stdin
%34 = call i32 @fileno(i32 %33)
%35 = load i32, i32* @TCSANOW
%36 = call i32 @tcsetattr(i32 %34, i32 %35, %struct.termios* %2)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %13
%39 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %13
%43 = call i32 (...) @do_something()
store i64 0, i64* @errno
%44 = load i32, i32* @stdin
%45 = call i32 @fileno(i32 %44)
%46 = load i32, i32* @TCSANOW
%47 = call i32 @tcsetattr(i32 %45, i32 %46, %struct.termios* %1)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %42
%54 = load i32, i32* @EXIT_SUCCESS
%55 = call i32 @exit(i32 %54)
unreachable
}