#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;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
scalar_t__ config_tty(int /*<<< orphan*/ *const, struct termios *);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *const);
scalar_t__ isatty(int /*<<< orphan*/);
scalar_t__ restore_tty(int /*<<< orphan*/ *const, struct termios *);
int /*<<< orphan*/ roll_bits(int /*<<< orphan*/ *const,
                             int /*<<< orphan*/ *const,
                             int /*<<< orphan*/ *const, int, int);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ warn(char *);
int main() {
  FILE *const in = stdin;
  FILE *const out = stdout;
  FILE *const err = stderr;
  int is_interactive = 0;
  int is_extended = 0;
  int tty_changed = 0;
  struct termios prev_tattr;
  if (isatty(fileno(in))) {
    is_interactive = 1;
    tty_changed = (config_tty(in, &prev_tattr) == 0);
    if (tty_changed == 0)
      error("ERROR: Unable to configure terminal");
  }
  roll_bits(in, out, err, is_interactive, is_extended);
  if (is_interactive != 0 && tty_changed != 0) {
    if (restore_tty(in, &prev_tattr) != 0)
      warn("WARNING: Unable to restore terminal settings");
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
cmp    $0x0,%rax
je     1226 <main+0xa6>
movl   $0x1,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <config_tty@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1221 <main+0xa1>
lea    0xde4(%rip),%rdi
call   1080 <error@plt>
jmp    1226 <main+0xa6>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
call   1060 <roll_bits@plt>
cmpl   $0x0,-0x24(%rbp)
je     127a <main+0xfa>
cmpl   $0x0,-0x2c(%rbp)
je     127a <main+0xfa>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <restore_tty@plt>
cmp    $0x0,%rax
je     1275 <main+0xf5>
lea    0xdb4(%rip),%rdi
call   1030 <warn@plt>
jmp    127a <main+0xfa>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%rbx
mov    0x2e36(%rip),%rax
mov    (%rax),%r14
mov    0x2e34(%rip),%rax
mov    (%rax),%r15
mov    %rbx,%rdi
call   1050 <fileno@plt>
mov    %eax,%edi
call   1040 <isatty@plt>
xor    %ecx,%ecx
test   %rax,%rax
je     1216 <main+0x96>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <config_tty@plt>
test   %rax,%rax
jne    1205 <main+0x85>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1060 <roll_bits@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <restore_tty@plt>
test   %rax,%rax
je     1227 <main+0xa7>
lea    0xe26(%rip),%rdi
call   1030 <warn@plt>
jmp    1227 <main+0xa7>
lea    0xdf4(%rip),%rdi
call   1080 <error@plt>
mov    $0x1,%ecx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %r8d,%r8d
call   1060 <roll_bits@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@.str = [36 x i8] c"ERROR: Unable to configure terminal\00"
@.str.1 = [45 x i8] c"WARNING: Unable to restore terminal settings\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
store i32 0, i32* %1
%9 = load i32*, i32** @stdin
store i32* %9, i32** %2
%10 = load i32*, i32** @stdout
store i32* %10, i32** %3
%11 = load i32*, i32** @stderr
store i32* %11, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%12 = load i32*, i32** %2
%13 = call i32 @fileno(i32* %12)
%14 = call i64 @isatty(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %0
store i32 1, i32* %5
%17 = load i32*, i32** %2
%18 = call i64 @config_tty(i32* %17, %struct.termios* %8)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
br label %26
26: ; preds = %25, %0
%27 = load i32*, i32** %2
%28 = load i32*, i32** %3
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i32 @roll_bits(i32* %27, i32* %28, i32* %29, i32 %30, i32 %31)
%33 = load i32, i32* %5
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %26
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = load i32*, i32** %2
%40 = call i64 @restore_tty(i32* %39, %struct.termios* %8)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
br label %45
45: ; preds = %44, %35, %26
%46 = load i32, i32* @EXIT_SUCCESS
%47 = call i32 @exit(i32 %46)
unreachable
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stdin = global i32* null
@stdout = global i32* null
@stderr = global i32* null
@.str = [36 x i8] c"ERROR: Unable to configure terminal\00"
@.str.1 = [45 x i8] c"WARNING: Unable to restore terminal settings\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.termios
%2 = load i32*, i32** @stdin
%3 = load i32*, i32** @stdout
%4 = load i32*, i32** @stderr
%5 = bitcast %struct.termios* %1 to i8*
%6 = tail call i32 @fileno(i32* %2)
%7 = tail call i64 @isatty(i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %0
%10 = call i64 @config_tty(i32* %2, %struct.termios* %1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = call i32 @error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %0, %12
%15 = phi i32 [ 0, %0 ], [ 1, %12 ]
%16 = call i32 @roll_bits(i32* %2, i32* %3, i32* %4, i32 %15, i32 0)
br label %23
17: ; preds = %9
%18 = call i32 @roll_bits(i32* %2, i32* %3, i32* %4, i32 1, i32 0)
%19 = call i64 @restore_tty(i32* %2, %struct.termios* %1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %17
%22 = call i32 @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %14, %17, %21
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @exit(i32 %24)
unreachable
}