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

/* Variables and functions */
int ECHO;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int main(int argc, char *argv[]) {
  struct termios info;
  if (tcgetattr(0, &info) == -1) {
    perror("tcgetattr");
    exit(EXIT_FAILURE);
  }
  if (info.c_lflag & ECHO) {
    printf("echo is on, since its bit is 1\n");
  } else {
    printf("echo is off, since its bit is 0\n");
  }
  return EXIT_SUCCESS;
}


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   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1184 <main+0x44>
lea    0xe8f(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
mov    0x2e5a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11aa <main+0x6a>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
jmp    11b6 <main+0x76>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rsi
xor    %edi,%edi
call   1040 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     117e <main+0x3e>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xea7(%rip),%rax
lea    0xec0(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    0x2e56(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret
lea    0xe7b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@EXIT_FAILURE = global i32 0
@ECHO = global i32 0
@.str.1 = [32 x i8] c"echo is on, since its bit is 1\0A\00"
@.str.2 = [33 x i8] c"echo is off, since its bit is 0\0A\00"
@EXIT_SUCCESS = 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 ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* @ECHO
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %23
21: ; preds = %13
%22 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"tcgetattr\00"
@EXIT_FAILURE = global i32 0
@ECHO = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [32 x i8] c"echo is off, since its bit is 0\00"
@str.3 = [31 x i8] c"echo is on, since its bit is 1\00"
define i32 @main(i32 %0, i8** nocapture readnone %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 ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @ECHO
%15 = and i32 %14, %13
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.3, i64 0, i64 0)
%18 = call i32 @puts(i8* dereferenceable(1) %17)
%19 = load i32, i32* @EXIT_SUCCESS
ret i32 %19
}