#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 */
typedef int uint8_t;
struct termios {
  int c_lflag;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ new_bit(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(void) {
  int i;
  uint8_t c;
  struct termios old_tio, new_tio;
  fprintf(stderr,
          "Decoding input binary stream as AX.25 packets. Debug level: %d.\n",
          0);
  tcgetattr(STDIN_FILENO, &old_tio);
  new_tio = old_tio;
  new_tio.c_lflag &= (~ICANON & ~ECHO);
  tcsetattr(STDIN_FILENO, TCSANOW, &new_tio);
  do {
    c = getchar();
    new_bit(c == '1' ? 1 : 0);
  } while (c != 255);
  tcsetattr(STDIN_FILENO, TCSANOW, &old_tio);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
xor    %edx,%edx
call   1040 <fprintf@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1070 <tcsetattr@plt>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %edi,%edi
mov    $0x1,%eax
cmp    $0x31,%ecx
cmove  %eax,%edi
call   1050 <new_bit@plt>
cmpl   $0xff,-0xc(%rbp)
jne    11c9 <main+0x79>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
xor    %edx,%edx
call   1040 <fprintf@plt>
mov    0x2e51(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rsi
call   1060 <tcgetattr@plt>
mov    0x2e37(%rip),%rax
mov    0x2e50(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    (%rsp),%ecx
mov    %ecx,0x8(%rsp)
mov    (%r14),%edi
mov    0x2e41(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%rdx
call   1070 <tcsetattr@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <getchar@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x31,%eax
sete   %dil
call   1050 <new_bit@plt>
cmp    $0xff,%ebx
jne    11c0 <main+0x70>
mov    (%r14),%edi
mov    (%r15),%esi
mov    %rsp,%rdx
call   1070 <tcsetattr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [65 x i8] c"Decoding input binary stream as AX.25 packets. Debug level: %d.\0A\00"
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
%5 = alloca %struct.termios
store i32 0, i32* %1
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = load i32, i32* @STDIN_FILENO
%9 = call i32 @tcgetattr(i32 %8, %struct.termios* %4)
%10 = bitcast %struct.termios* %5 to i8*
%11 = bitcast %struct.termios* %4 to i8*
%12 = load i32, i32* @ICANON
%13 = xor i32 %12, -1
%14 = load i32, i32* @ECHO
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = and i32 %18, %16
store i32 %19, i32* %17
%20 = load i32, i32* @STDIN_FILENO
%21 = load i32, i32* @TCSANOW
%22 = call i32 @tcsetattr(i32 %20, i32 %21, %struct.termios* %5)
br label %23
23: ; preds = %30, %0
%24 = call i32 (...) @getchar()
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp eq i32 %25, 49
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 1, i32 0
%29 = call i32 @new_bit(i32 %28)
br label %30
30: ; preds = %23
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 255
br i1 %32, label %23, label %33
33: ; preds = %30
%34 = load i32, i32* @STDIN_FILENO
%35 = load i32, i32* @TCSANOW
%36 = call i32 @tcsetattr(i32 %34, i32 %35, %struct.termios* %4)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@stderr = global i32 0
@.str = [65 x i8] c"Decoding input binary stream as AX.25 packets. Debug level: %d.\0A\00"
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
define i32 @main() {
%1 = alloca %struct.termios
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %1 to i8*
%4 = bitcast %struct.termios* %2 to i8*
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i32 0)
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @tcgetattr(i32 %7, %struct.termios* %1)
%9 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%10 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%11 = load i32, i32* %9
%12 = load i32, i32* @ICANON
%13 = load i32, i32* @ECHO
%14 = or i32 %13, %12
%15 = xor i32 %14, -1
%16 = and i32 %11, %15
store i32 %16, i32* %10
%17 = load i32, i32* @STDIN_FILENO
%18 = load i32, i32* @TCSANOW
%19 = call i32 @tcsetattr(i32 %17, i32 %18, %struct.termios* %2)
br label %20
20: ; preds = %20, %0
%21 = call i32 (...) @getchar()
%22 = icmp eq i32 %21, 49
%23 = zext i1 %22 to i32
%24 = call i32 @new_bit(i32 %23)
%25 = icmp eq i32 %21, 255
br i1 %25, label %26, label %20
26: ; preds = %20
%27 = load i32, i32* @STDIN_FILENO
%28 = load i32, i32* @TCSANOW
%29 = call i32 @tcsetattr(i32 %27, i32 %28, %struct.termios* %1)
ret i32 0
}