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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ ISTRIP;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int /*<<< orphan*/, struct termios *);
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
void set_terminal_modes(struct termios *initial_status) {
  if (tcgetattr(0, initial_status)) {
    fprintf(stderr, "Could not get state of current terminal: %s\n",
            strerror(errno));
    exit(EXIT_FAILURE);
  }
  struct termios *set_status = initial_status;
  set_status->c_iflag = ISTRIP;
  set_status->c_oflag = 0;
  set_status->c_lflag = 0;
  if (tcsetattr(0, TCSANOW, set_status)) {
    fprintf(stderr, "Could not set status of current terminal: %s",
            strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<set_terminal_modes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     11ab <set_terminal_modes+0x5b>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe68(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
xor    %edi,%edi
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
je     1232 <set_terminal_modes+0xe2>
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe0e(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_terminal_modes>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
jne    118f <set_terminal_modes+0x3f>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rbx)
xorps  %xmm0,%xmm0
movups %xmm0,(%rbx)
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
test   %rax,%rax
jne    11af <set_terminal_modes+0x5f>
pop    %rbx
ret
mov    0x2e42(%rip),%rax
mov    (%rax),%ebx
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe53(%rip),%rsi
jmp    11cd <set_terminal_modes+0x7d>
mov    0x2e22(%rip),%rax
mov    (%rax),%ebx
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe60(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i64, i64, i32 }
@stderr = global i32 0
@.str = [45 x i8] c"Could not get state of current terminal: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@ISTRIP = global i32 0
@TCSANOW = global i32 0
@.str.1 = [45 x i8] c"Could not set status of current terminal: %s\00"
define void @set_terminal_modes(%struct.termios* %0) {
%2 = alloca %struct.termios*
%3 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %2
%4 = load %struct.termios*, %struct.termios** %2
%5 = call i64 @tcgetattr(i32 0, %struct.termios* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = load %struct.termios*, %struct.termios** %2
store %struct.termios* %15, %struct.termios** %3
%16 = load i32, i32* @ISTRIP
%17 = load %struct.termios*, %struct.termios** %3
%18 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 2
store i32 %16, i32* %18
%19 = load %struct.termios*, %struct.termios** %3
%20 = getelementptr inbounds %struct.termios, %struct.termios* %19, i32 0, i32 1
store i64 0, i64* %20
%21 = load %struct.termios*, %struct.termios** %3
%22 = getelementptr inbounds %struct.termios, %struct.termios* %21, i32 0, i32 0
store i64 0, i64* %22
%23 = load i32, i32* @TCSANOW
%24 = load %struct.termios*, %struct.termios** %3
%25 = call i64 @tcsetattr(i32 0, i32 %23, %struct.termios* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %14
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.termios = type { i64, i64, i32 }
@stderr = global i32 0
@.str = [45 x i8] c"Could not get state of current terminal: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@ISTRIP = global i32 0
@TCSANOW = global i32 0
@.str.1 = [45 x i8] c"Could not set status of current terminal: %s\00"
define void @set_terminal_modes(%struct.termios* %0) {
%2 = tail call i64 @tcgetattr(i32 0, %struct.termios* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %11, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* @ISTRIP
%13 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 2
store i32 %12, i32* %13
%14 = bitcast %struct.termios* %0 to i8*
%15 = load i32, i32* @TCSANOW
%16 = tail call i64 @tcsetattr(i32 0, i32 %15, %struct.termios* %0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = tail call i8* @strerror(i32 %20)
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %11
ret void
}