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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int changeTermSettings(struct termios new_settings) {
  struct termios actual_settings;
  if (tcsetattr(STDIN_FILENO, TCSANOW, &new_settings) == -1) {
    return -1;
  }
  memset(&actual_settings, 0, sizeof(struct termios));
  if (tcgetattr(STDIN_FILENO, &actual_settings) == -1) {
    return -1;
  } else {
    if (new_settings.c_lflag != actual_settings.c_lflag) {
      return -1;
    } else {
      return 0;
    }
  }
}


x86 assembly (clang, -O0):
<changeTermSettings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0xffffffff,%eax
jne    116c <changeTermSettings+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <changeTermSettings+0x94>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11a3 <changeTermSettings+0x73>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <changeTermSettings+0x94>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11bd <changeTermSettings+0x8d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <changeTermSettings+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeTermSettings>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,(%rsp)
mov    0x2e94(%rip),%r15
mov    (%r15),%edi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1050 <tcsetattr@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1196 <changeTermSettings+0x66>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    (%r15),%edi
mov    %r14,%rsi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     1196 <changeTermSettings+0x66>
mov    (%rsp),%rax
xor    %ebx,%ebx
cmp    0x8(%rsp),%rax
setne  %bl
neg    %ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i64 }
@STDIN_FILENO = global i32 0
@TCSANOW = global i32 0
define i32 @changeTermSettings(i64 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
%4 = alloca %struct.termios
%5 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
store i64 %0, i64* %5
%6 = load i32, i32* @STDIN_FILENO
%7 = load i32, i32* @TCSANOW
%8 = call i32 @tcsetattr(i32 %6, i32 %7, %struct.termios* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %25
11: ; preds = %1
%12 = call i32 @memset(%struct.termios* %4, i32 0, i32 8)
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @tcgetattr(i32 %13, %struct.termios* %4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 -1, i32* %2
br label %25
17: ; preds = %11
%18 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%21 = load i64, i64* %20
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %2
br label %25
24: ; preds = %17
store i32 0, i32* %2
br label %25
25: ; preds = %24, %23, %16, %10
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.termios = type { i64 }
@STDIN_FILENO = global i32 0
@TCSANOW = global i32 0
define i32 @changeTermSettings(i64 %0) {
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i64 %0, i64* %4
%5 = bitcast %struct.termios* %3 to i8*
%6 = load i32, i32* @STDIN_FILENO
%7 = load i32, i32* @TCSANOW
%8 = call i32 @tcsetattr(i32 %6, i32 %7, %struct.termios* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %21, label %10
10: ; preds = %1
%11 = call i32 @memset(%struct.termios* %3, i32 0, i32 8)
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @tcgetattr(i32 %12, %struct.termios* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = load i64, i64* %4
%17 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%18 = load i64, i64* %17
%19 = icmp ne i64 %16, %18
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %15, %10, %1
%22 = phi i32 [ -1, %1 ], [ -1, %10 ], [ %20, %15 ]
ret i32 %22
}