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

/* Variables and functions */
int /*<<< orphan*/ ECHO;
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ TCSANOW;
int fgetc(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int mpb_get_choice(void) {
  int choice = -1;
  struct termios initialrsettings;
  struct termios newrsettings;
  tcgetattr(fileno(stdin), &initialrsettings);
  newrsettings = initialrsettings;
  newrsettings.c_lflag &= ~ICANON;
  newrsettings.c_lflag &= ~ECHO;
  if (0 != tcsetattr(fileno(stdin), TCSAFLUSH, &newrsettings)) {
    fprintf(stderr, "Could not set attributes\n");
  } else {
    choice = fgetc(stdin);
    tcsetattr(fileno(stdin), TCSANOW, &initialrsettings);
  }
  return choice;
}


x86 assembly (clang, -O0):
<mpb_get_choice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xffffffff,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
lea    -0x8(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11ec <mpb_get_choice+0x9c>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    121f <mpb_get_choice+0xcf>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1030 <fgetc@plt>
mov    %eax,-0x4(%rbp)
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpb_get_choice>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e82(%rip),%r14
mov    (%r14),%edi
call   1050 <fileno@plt>
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1060 <tcgetattr@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    0x2e4e(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    0x8(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    (%r14),%edi
call   1050 <fileno@plt>
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%esi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
call   1070 <tcsetattr@plt>
test   %rax,%rax
je     11cc <mpb_get_choice+0x7c>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11f3 <mpb_get_choice+0xa3>
mov    (%r14),%edi
call   1030 <fgetc@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1050 <fileno@plt>
mov    0x2df3(%rip),%rcx
mov    (%rcx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1070 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Could not set attributes\0A\00"
@TCSANOW = global i32 0
define i32 @mpb_get_choice() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
store i32 -1, i32* %1
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = call i32 @tcgetattr(i32 %5, %struct.termios* %2)
%7 = bitcast %struct.termios* %3 to i8*
%8 = bitcast %struct.termios* %2 to i8*
%9 = load i32, i32* @ICANON
%10 = xor i32 %9, -1
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = and i32 %12, %10
store i32 %13, i32* %11
%14 = load i32, i32* @ECHO
%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* @stdin
%20 = call i32 @fileno(i32 %19)
%21 = load i32, i32* @TCSAFLUSH
%22 = call i64 @tcsetattr(i32 %20, i32 %21, %struct.termios* %3)
%23 = icmp ne i64 0, %22
br i1 %23, label %24, label %27
24: ; preds = %0
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %34
27: ; preds = %0
%28 = load i32, i32* @stdin
%29 = call i32 @fgetc(i32 %28)
store i32 %29, i32* %1
%30 = load i32, i32* @stdin
%31 = call i32 @fileno(i32 %30)
%32 = load i32, i32* @TCSANOW
%33 = call i64 @tcsetattr(i32 %31, i32 %32, %struct.termios* %2)
br label %34
34: ; preds = %27, %24
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSAFLUSH = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"Could not set attributes\0A\00"
@TCSANOW = global i32 0
define i32 @mpb_get_choice() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
%5 = load i32, i32* @stdin
%6 = tail call i32 @fileno(i32 %5)
%7 = call i32 @tcgetattr(i32 %6, %struct.termios* %1)
%8 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%10 = load i32, i32* %8
%11 = load i32, i32* @ICANON
%12 = load i32, i32* @ECHO
%13 = or i32 %11, %12
%14 = xor i32 %13, -1
%15 = and i32 %10, %14
store i32 %15, i32* %9
%16 = load i32, i32* @stdin
%17 = call i32 @fileno(i32 %16)
%18 = load i32, i32* @TCSAFLUSH
%19 = call i64 @tcsetattr(i32 %17, i32 %18, %struct.termios* %2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %0
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %31
24: ; preds = %0
%25 = load i32, i32* @stdin
%26 = call i32 @fgetc(i32 %25)
%27 = load i32, i32* @stdin
%28 = call i32 @fileno(i32 %27)
%29 = load i32, i32* @TCSANOW
%30 = call i64 @tcsetattr(i32 %28, i32 %29, %struct.termios* %1)
br label %31
31: ; preds = %24, %21
%32 = phi i32 [ -1, %21 ], [ %26, %24 ]
ret i32 %32
}