#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ parse_args(struct termios *, int, char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_settings(struct termios *);
int /*<<< orphan*/ save_tty(struct termios *);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  struct termios ttyp;
  if (tcgetattr(0, &ttyp) == -1) {
    perror("Unable to retrieve terminal settings");
    exit(EXIT_FAILURE);
  }
  if (argc <= 1)
    print_settings(&ttyp);
  parse_args(&ttyp, argc, argv);
  save_tty(&ttyp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1060 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11a4 <main+0x44>
lea    0xe6f(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jg     11b7 <main+0x57>
lea    -0x18(%rbp),%rdi
call   1030 <print_settings@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
call   1040 <parse_args@plt>
lea    -0x18(%rbp),%rdi
call   1050 <save_tty@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1060 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11b2 <main+0x52>
cmp    $0x1,%ebp
jg     118d <main+0x2d>
lea    0x8(%rsp),%rdi
call   1030 <print_settings@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <parse_args@plt>
mov    %rbx,%rdi
call   1050 <save_tty@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [37 x i8] c"Unable to retrieve terminal settings\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @tcgetattr(i32 0, %struct.termios* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @print_settings(%struct.termios* %6)
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i32 @parse_args(%struct.termios* %6, i32 %19, i8** %20)
%22 = call i32 @save_tty(%struct.termios* %6)
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [37 x i8] c"Unable to retrieve terminal settings\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = call i32 @print_settings(%struct.termios* %3)
br label %15
15: ; preds = %13, %11
%16 = call i32 @parse_args(%struct.termios* %3, i32 %0, i8** %1)
%17 = call i32 @save_tty(%struct.termios* %3)
ret i32 0
}