#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 /*<<< 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;
  int val;
  val = tcgetattr(0, &info);
  if (val == -1) {
    perror("tcgetattr() failed");
    exit(EXIT_FAILURE);
  }
  if (info.c_lflag & ECHO)
    printf("echo is on\n");
  else
    printf("echo is off\n");
  return 0;
}


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>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1188 <main+0x48>
lea    0xe8b(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
mov    0x2e56(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ae <main+0x6e>
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
jmp    11ba <main+0x7a>
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%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     1177 <main+0x37>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
lea    0xeb0(%rip),%rax
lea    0xeb5(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [19 x i8] c"tcgetattr() failed\00"
@EXIT_FAILURE = global i32 0
@ECHO = global i32 0
@.str.1 = [12 x i8] c"echo is on\0A\00"
@.str.2 = [13 x i8] c"echo is off\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @tcgetattr(i32 0, %struct.termios* %6)
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @ECHO
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [19 x i8] c"tcgetattr() failed\00"
@EXIT_FAILURE = global i32 0
@ECHO = global i32 0
@str = [12 x i8] c"echo is off\00"
@str.3 = [11 x i8] c"echo is on\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 ([19 x i8], [19 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 ([12 x i8], [12 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @str.3, i64 0, i64 0)
%18 = call i32 @puts(i8* dereferenceable(1) %17)
ret i32 0
}