#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int load_term(struct termios *termios_p) {
  if (tcsetattr(fileno(stdin), TCSANOW, termios_p) != 0) {
    fprintf(stderr, "Failed to load terminal settings");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<load_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    %eax,%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
je     1189 <load_term+0x59>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <load_term+0x60>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_term>:
push   %rbx
mov    %rdi,%rbx
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
call   1040 <fileno@plt>
mov    0x2e97(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
mov    %rbx,%rdx
call   1050 <tcsetattr@plt>
test   %rax,%rax
je     1176 <load_term+0x46>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32 0
@TCSANOW = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Failed to load terminal settings\00"
define i32 @load_term(%struct.termios* %0) {
%2 = alloca i32
%3 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %3
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = load i32, i32* @TCSANOW
%7 = load %struct.termios*, %struct.termios** %3
%8 = call i64 @tcsetattr(i32 %5, i32 %6, %struct.termios* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32 0
@TCSANOW = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"Failed to load terminal settings\00"
define i32 @load_term(%struct.termios* %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32 @fileno(i32 %2)
%4 = load i32, i32* @TCSANOW
%5 = tail call i64 @tcsetattr(i32 %3, i32 %4, %struct.termios* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %1, %7
%11 = phi i32 [ -1, %7 ], [ 0, %1 ]
ret i32 %11
}