#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_iflag;
  int c_oflag;
  int c_lflag;
  int /*<<< orphan*/ *c_cc;
};

/* Variables and functions */
int ECHO;
int ICANON;
int ICRNL;
int INLCR;
int IUCLC;
int IXON;
int OCRNL;
int OLCUC;
int ONLCR;
int ONLRET;
int OPOST;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int tcgetattr(int /*<<< orphan*/, struct termios *);
int tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int write(int, char *, int);
int main(int argc, char **argv) {
  char buf[0x100];
  int r, i;
  struct termios oldtios;
  printf("sizeof tios = %d\n", sizeof oldtios);
  printf("tios.c_cc = %d\n", (int)&((struct termios *)NULL)->c_cc[0]);
  r = tcgetattr(0, &oldtios);
  if (r < 0)
    return 1;
  printf("tios.c_iflag: (%08x) %s %s %s %s %s\n", oldtios.c_iflag,
         (oldtios.c_iflag & ICRNL) ? "ICRNL" : "~ICRNL",
         (oldtios.c_iflag & INLCR) ? "INLCR" : "~INLCR",
         (oldtios.c_iflag & IUCLC) ? "IUCLC" : "~IUCLC",
         (oldtios.c_iflag & IXON) ? "IXON" : "~IXON",
         (oldtios.c_iflag & IXON) ? "IXOFF" : "~IXOFF");
  printf("tios.c_oflag: (%08x) %s %s %s %s %s\n", oldtios.c_oflag,
         (oldtios.c_oflag & ONLRET) ? "ONLRET" : "~ONLRET",
         (oldtios.c_oflag & OCRNL) ? "OCRNL" : "~OCRNL",
         (oldtios.c_oflag & ONLCR) ? "ONLCR" : "~ONLCR",
         (oldtios.c_oflag & OLCUC) ? "OLCUC" : "~OLCUC",
         (oldtios.c_oflag & OPOST) ? "OPOST" : "~POST");
  printf("tios.c_lflag (%08x): %s %s\n", oldtios.c_lflag,
         (oldtios.c_lflag & ECHO) ? "ECHO" : "~ECHO",
         (oldtios.c_lflag & ICANON) ? "ICANON" : "~ICANON");
  if (argc < 2) {
    printf("Args are (can|raw)\n");
    return 1;
  }
  if (!strcmp(argv[1], "can")) {
    printf("Using canonical mode\n");
  } else if (!strcmp(argv[1], "can")) {
    struct termios tios;
    memset(&tios, 0, sizeof tios);
    r = tcgetattr(0, &tios);
    if (r < 0)
      return 1;
    tios.c_lflag &= ~ICANON;
    r = tcsetattr(0, 0, &tios);
    if (r < 0)
      return 1;
  }
  r = read(0, buf, sizeof buf);
  if (r > 0)
    r = write(1, buf, r);
  printf("read %d characters\n", r);
  for (i = 0; i < r; i++)
    printf("%02x ", buf[i]);
  printf("\n");
  tcsetattr(0, 0, &oldtios);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rdi
mov    $0x18,%esi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    0x10(%rax),%rax
mov    %eax,%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
lea    -0x130(%rbp),%rsi
call   1080 <tcgetattr@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    11df <main+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    15a4 <main+0x434>
mov    -0x130(%rbp),%esi
mov    -0x130(%rbp),%ecx
mov    0x2dee(%rip),%rax
and    (%rax),%ecx
lea    0xe4c(%rip),%rdx
lea    0xe46(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x130(%rbp),%edi
mov    0x2dc2(%rip),%rax
and    (%rax),%edi
lea    0xe2f(%rip),%rcx
lea    0xe29(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
mov    -0x130(%rbp),%edi
mov    0x2d66(%rip),%rax
and    (%rax),%edi
lea    0xe12(%rip),%r8
lea    0xe0c(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
mov    -0x130(%rbp),%edi
mov    0x2d6a(%rip),%rax
and    (%rax),%edi
lea    0xdf5(%rip),%r9
lea    0xdef(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r9
mov    -0x130(%rbp),%r10d
mov    0x2d45(%rip),%rax
and    (%rax),%r10d
lea    0xdd5(%rip),%rax
lea    0xdcf(%rip),%rdi
cmp    $0x0,%r10d
cmovne %rdi,%rax
lea    0xd7f(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x12c(%rbp),%esi
mov    -0x12c(%rbp),%ecx
mov    0x2cd7(%rip),%rax
and    (%rax),%ecx
lea    0xdc4(%rip),%rdx
lea    0xdbe(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x12c(%rbp),%edi
mov    0x2d0b(%rip),%rax
and    (%rax),%edi
lea    0xda8(%rip),%rcx
lea    0xda2(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
mov    -0x12c(%rbp),%edi
mov    0x2c9f(%rip),%rax
and    (%rax),%edi
lea    0xd8b(%rip),%r8
lea    0xd85(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
mov    -0x12c(%rbp),%edi
mov    0x2c8b(%rip),%rax
and    (%rax),%edi
lea    0xd6e(%rip),%r9
lea    0xd68(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r9
mov    -0x12c(%rbp),%r10d
mov    0x2c7e(%rip),%rax
and    (%rax),%r10d
lea    0xd55(%rip),%rax
lea    0xd48(%rip),%rdi
cmp    $0x0,%r10d
cmovne %rdi,%rax
lea    0xcf7(%rip),%rdi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x128(%rbp),%esi
mov    -0x128(%rbp),%ecx
mov    0x2c30(%rip),%rax
and    (%rax),%ecx
lea    0xd3a(%rip),%rdx
lea    0xd34(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x128(%rbp),%edi
mov    0x2bdc(%rip),%rax
and    (%rax),%edi
lea    0xd1c(%rip),%rcx
lea    0xd16(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    13fd <main+0x28d>
lea    0xcf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    15a4 <main+0x434>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xce9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    142d <main+0x2bd>
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14db <main+0x36b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcb9(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    14d6 <main+0x366>
lea    -0x148(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
xor    %edi,%edi
lea    -0x148(%rbp),%rsi
call   1080 <tcgetattr@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    148a <main+0x31a>
movl   $0x1,-0x4(%rbp)
jmp    15a4 <main+0x434>
mov    0x2aff(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x140(%rbp),%eax
mov    %eax,-0x140(%rbp)
xor    %esi,%esi
lea    -0x148(%rbp),%rdx
mov    %esi,%edi
call   1090 <tcsetattr@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jge    14d1 <main+0x361>
movl   $0x1,-0x4(%rbp)
jmp    15a4 <main+0x434>
jmp    14d6 <main+0x366>
jmp    14db <main+0x36b>
lea    -0x110(%rbp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    151e <main+0x3ae>
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    %eax,-0x114(%rbp)
mov    -0x114(%rbp),%esi
lea    0xbe4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x118(%rbp),%eax
cmp    -0x114(%rbp),%eax
jge    157f <main+0x40f>
movslq -0x118(%rbp),%rax
movsbl -0x110(%rbp,%rax,1),%esi
ff
lea    0xbbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    153c <main+0x3cc>
lea    0xb6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %esi,%esi
lea    -0x130(%rbp),%rdx
mov    %esi,%edi
call   1090 <tcsetattr@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe69(%rip),%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10,%esi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1090 <tcgetattr@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     1424 <main+0x2a4>
mov    0x8(%rsp),%esi
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xe60(%rip),%rax
lea    0xe5a(%rip),%rdx
cmove  %rax,%rdx
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xe4a(%rip),%rax
lea    0xe44(%rip),%rcx
cmove  %rax,%rcx
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xe34(%rip),%rax
lea    0xe2e(%rip),%r8
cmove  %rax,%r8
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xe1e(%rip),%rax
lea    0xe18(%rip),%r9
cmove  %rax,%r9
lea    0xe12(%rip),%rax
lea    0xe0c(%rip),%rdi
cmove  %rax,%rdi
mov    %rdi,(%rsp)
lea    0xdbc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0xc(%rsp),%esi
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xe0b(%rip),%rax
lea    0xe05(%rip),%rdx
cmove  %rax,%rdx
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xdf6(%rip),%rax
lea    0xdf0(%rip),%rcx
cmove  %rax,%rcx
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xde0(%rip),%rax
lea    0xdda(%rip),%r8
cmove  %rax,%r8
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xdca(%rip),%rax
lea    0xdc4(%rip),%r9
cmove  %rax,%r9
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xdba(%rip),%rax
lea    0xdad(%rip),%rdi
cmove  %rax,%rdi
mov    %rdi,(%rsp)
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
mov    0x2ca1(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xda9(%rip),%rax
lea    0xda3(%rip),%rdx
cmove  %rax,%rdx
mov    0x2c54(%rip),%rax
mov    (%rax),%eax
and    %esi,%eax
lea    0xd92(%rip),%rax
lea    0xd8c(%rip),%rcx
cmove  %rax,%rcx
lea    0xd5e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%ebp
jg     1376 <main+0x1f6>
lea    0xda8(%rip),%rdi
call   1040 <puts@plt>
jmp    1424 <main+0x2a4>
mov    0x8(%r14),%rdi
lea    0xd60(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    1396 <main+0x216>
lea    0xd6e(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
xor    %edi,%edi
mov    $0x100,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    13fa <main+0x27a>
lea    0x20(%rsp),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,%ebx
lea    0xd20(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,%ebx
jle    140a <main+0x28a>
mov    %ebx,%ebp
lea    0xd1e(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
movsbl 0x20(%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    13e0 <main+0x260>
jmp    140a <main+0x28a>
lea    0xce4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
xor    %esi,%esi
call   10a0 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32* }
@.str = [18 x i8] c"sizeof tios = %d\0A\00"
@.str.1 = [16 x i8] c"tios.c_cc = %d\0A\00"
@.str.2 = [37 x i8] c"tios.c_iflag: (%08x) %s %s %s %s %s\0A\00"
@ICRNL = global i32 0
@.str.3 = [6 x i8] c"ICRNL\00"
@.str.4 = [7 x i8] c"~ICRNL\00"
@INLCR = global i32 0
@.str.5 = [6 x i8] c"INLCR\00"
@.str.6 = [7 x i8] c"~INLCR\00"
@IUCLC = global i32 0
@.str.7 = [6 x i8] c"IUCLC\00"
@.str.8 = [7 x i8] c"~IUCLC\00"
@IXON = global i32 0
@.str.9 = [5 x i8] c"IXON\00"
@.str.10 = [6 x i8] c"~IXON\00"
@.str.11 = [6 x i8] c"IXOFF\00"
@.str.12 = [7 x i8] c"~IXOFF\00"
@.str.13 = [37 x i8] c"tios.c_oflag: (%08x) %s %s %s %s %s\0A\00"
@ONLRET = global i32 0
@.str.14 = [7 x i8] c"ONLRET\00"
@.str.15 = [8 x i8] c"~ONLRET\00"
@OCRNL = global i32 0
@.str.16 = [6 x i8] c"OCRNL\00"
@.str.17 = [7 x i8] c"~OCRNL\00"
@ONLCR = global i32 0
@.str.18 = [6 x i8] c"ONLCR\00"
@.str.19 = [7 x i8] c"~ONLCR\00"
@OLCUC = global i32 0
@.str.20 = [6 x i8] c"OLCUC\00"
@.str.21 = [7 x i8] c"~OLCUC\00"
@OPOST = global i32 0
@.str.22 = [6 x i8] c"OPOST\00"
@.str.23 = [6 x i8] c"~POST\00"
@.str.24 = [28 x i8] c"tios.c_lflag (%08x): %s %s\0A\00"
@ECHO = global i32 0
@.str.25 = [5 x i8] c"ECHO\00"
@.str.26 = [6 x i8] c"~ECHO\00"
@ICANON = global i32 0
@.str.27 = [7 x i8] c"ICANON\00"
@.str.28 = [8 x i8] c"~ICANON\00"
@.str.29 = [20 x i8] c"Args are (can|raw)\0A\00"
@.str.30 = [4 x i8] c"can\00"
@.str.31 = [22 x i8] c"Using canonical mode\0A\00"
@.str.32 = [20 x i8] c"read %d characters\0A\00"
@.str.33 = [6 x i8] c"%02x \00"
@.str.34 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.termios
%10 = alloca %struct.termios
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 24)
%12 = load i32*, i32** getelementptr inbounds (%struct.termios, %struct.termios* null, i32 0, i32 3)
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = ptrtoint i32* %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @tcgetattr(i32 0, %struct.termios* %9)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 1, i32* %3
br label %179
20: ; preds = %2
%21 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%24 = load i32, i32* %23
%25 = load i32, i32* @ICRNL
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0)
%30 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%31 = load i32, i32* %30
%32 = load i32, i32* @INLCR
%33 = and i32 %31, %32
%34 = icmp ne i32 %33, 0
%35 = zext i1 %34 to i64
%36 = select i1 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0)
%37 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%38 = load i32, i32* %37
%39 = load i32, i32* @IUCLC
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0)
%44 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load i32, i32* @IXON
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0)
%51 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* @IXON
%54 = and i32 %52, %53
%55 = icmp ne i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %22, i8* %29, i8* %36, i8* %43, i8* %50, i8* %57)
%59 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%60 = load i32, i32* %59
%61 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%62 = load i32, i32* %61
%63 = load i32, i32* @ONLRET
%64 = and i32 %62, %63
%65 = icmp ne i32 %64, 0
%66 = zext i1 %65 to i64
%67 = select i1 %65, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0)
%68 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%69 = load i32, i32* %68
%70 = load i32, i32* @OCRNL
%71 = and i32 %69, %70
%72 = icmp ne i32 %71, 0
%73 = zext i1 %72 to i64
%74 = select i1 %72, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0)
%75 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%76 = load i32, i32* %75
%77 = load i32, i32* @ONLCR
%78 = and i32 %76, %77
%79 = icmp ne i32 %78, 0
%80 = zext i1 %79 to i64
%81 = select i1 %79, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.19, i64 0, i64 0)
%82 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%83 = load i32, i32* %82
%84 = load i32, i32* @OLCUC
%85 = and i32 %83, %84
%86 = icmp ne i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.21, i64 0, i64 0)
%89 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 1
%90 = load i32, i32* %89
%91 = load i32, i32* @OPOST
%92 = and i32 %90, %91
%93 = icmp ne i32 %92, 0
%94 = zext i1 %93 to i64
%95 = select i1 %93, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.23, i64 0, i64 0)
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i32 %60, i8* %67, i8* %74, i8* %81, i8* %88, i8* %95)
%97 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%98 = load i32, i32* %97
%99 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%100 = load i32, i32* %99
%101 = load i32, i32* @ECHO
%102 = and i32 %100, %101
%103 = icmp ne i32 %102, 0
%104 = zext i1 %103 to i64
%105 = select i1 %103, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.26, i64 0, i64 0)
%106 = getelementptr inbounds %struct.termios, %struct.termios* %9, i32 0, i32 2
%107 = load i32, i32* %106
%108 = load i32, i32* @ICANON
%109 = and i32 %107, %108
%110 = icmp ne i32 %109, 0
%111 = zext i1 %110 to i64
%112 = select i1 %110, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.27, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0)
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0), i32 %98, i8* %105, i8* %112)
%114 = load i32, i32* %4
%115 = icmp slt i32 %114, 2
br i1 %115, label %116, label %118
116: ; preds = %20
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.29, i64 0, i64 0))
store i32 1, i32* %3
br label %179
118: ; preds = %20
%119 = load i8**, i8*** %5
%120 = getelementptr inbounds i8*, i8** %119, i64 1
%121 = load i8*, i8** %120
%122 = call i32 @strcmp(i8* %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.30, i64 0, i64 0))
%123 = icmp ne i32 %122, 0
br i1 %123, label %126, label %124
124: ; preds = %118
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.31, i64 0, i64 0))
br label %150
126: ; preds = %118
%127 = load i8**, i8*** %5
%128 = getelementptr inbounds i8*, i8** %127, i64 1
%129 = load i8*, i8** %128
%130 = call i32 @strcmp(i8* %129, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.30, i64 0, i64 0))
%131 = icmp ne i32 %130, 0
br i1 %131, label %149, label %132
132: ; preds = %126
%133 = call i32 @memset(%struct.termios* %10, i32 0, i32 24)
%134 = call i32 @tcgetattr(i32 0, %struct.termios* %10)
store i32 %134, i32* %7
%135 = load i32, i32* %7
%136 = icmp slt i32 %135, 0
br i1 %136, label %137, label %138
137: ; preds = %132
store i32 1, i32* %3
br label %179
138: ; preds = %132
%139 = load i32, i32* @ICANON
%140 = xor i32 %139, -1
%141 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 2
%142 = load i32, i32* %141
%143 = and i32 %142, %140
store i32 %143, i32* %141
%144 = call i32 @tcsetattr(i32 0, i32 0, %struct.termios* %10)
store i32 %144, i32* %7
%145 = load i32, i32* %7
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %148
147: ; preds = %138
store i32 1, i32* %3
br label %179
148: ; preds = %138
br label %149
149: ; preds = %148, %126
br label %150
150: ; preds = %149, %124
%151 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%152 = call i32 @read(i32 0, i8* %151, i32 256)
store i32 %152, i32* %7
%153 = load i32, i32* %7
%154 = icmp sgt i32 %153, 0
br i1 %154, label %155, label %159
155: ; preds = %150
%156 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%157 = load i32, i32* %7
%158 = call i32 @write(i32 1, i8* %156, i32 %157)
store i32 %158, i32* %7
br label %159
159: ; preds = %155, %150
%160 = load i32, i32* %7
%161 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.32, i64 0, i64 0), i32 %160)
store i32 0, i32* %8
br label %162
162: ; preds = %173, %159
%163 = load i32, i32* %8
%164 = load i32, i32* %7
%165 = icmp slt i32 %163, %164
br i1 %165, label %166, label %176
166: ; preds = %162
%167 = load i32, i32* %8
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %168
%170 = load i8, i8* %169
%171 = sext i8 %170 to i32
%172 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.33, i64 0, i64 0), i32 %171)
br label %173
173: ; preds = %166
%174 = load i32, i32* %8
%175 = add nsw i32 %174, 1
store i32 %175, i32* %8
br label %162
176: ; preds = %162
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.34, i64 0, i64 0))
%178 = call i32 @tcsetattr(i32 0, i32 0, %struct.termios* %9)
store i32 0, i32* %3
br label %179
179: ; preds = %176, %147, %137, %116, %19
%180 = load i32, i32* %3
ret i32 %180
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32* }
@.str = [18 x i8] c"sizeof tios = %d\0A\00"
@.str.1 = [16 x i8] c"tios.c_cc = %d\0A\00"
@.str.2 = [37 x i8] c"tios.c_iflag: (%08x) %s %s %s %s %s\0A\00"
@ICRNL = global i32 0
@.str.3 = [6 x i8] c"ICRNL\00"
@.str.4 = [7 x i8] c"~ICRNL\00"
@INLCR = global i32 0
@.str.5 = [6 x i8] c"INLCR\00"
@.str.6 = [7 x i8] c"~INLCR\00"
@IUCLC = global i32 0
@.str.7 = [6 x i8] c"IUCLC\00"
@.str.8 = [7 x i8] c"~IUCLC\00"
@IXON = global i32 0
@.str.9 = [5 x i8] c"IXON\00"
@.str.10 = [6 x i8] c"~IXON\00"
@.str.11 = [6 x i8] c"IXOFF\00"
@.str.12 = [7 x i8] c"~IXOFF\00"
@.str.13 = [37 x i8] c"tios.c_oflag: (%08x) %s %s %s %s %s\0A\00"
@ONLRET = global i32 0
@.str.14 = [7 x i8] c"ONLRET\00"
@.str.15 = [8 x i8] c"~ONLRET\00"
@OCRNL = global i32 0
@.str.16 = [6 x i8] c"OCRNL\00"
@.str.17 = [7 x i8] c"~OCRNL\00"
@ONLCR = global i32 0
@.str.18 = [6 x i8] c"ONLCR\00"
@.str.19 = [7 x i8] c"~ONLCR\00"
@OLCUC = global i32 0
@.str.20 = [6 x i8] c"OLCUC\00"
@.str.21 = [7 x i8] c"~OLCUC\00"
@OPOST = global i32 0
@.str.22 = [6 x i8] c"OPOST\00"
@.str.23 = [6 x i8] c"~POST\00"
@.str.24 = [28 x i8] c"tios.c_lflag (%08x): %s %s\0A\00"
@ECHO = global i32 0
@.str.25 = [5 x i8] c"ECHO\00"
@.str.26 = [6 x i8] c"~ECHO\00"
@ICANON = global i32 0
@.str.27 = [7 x i8] c"ICANON\00"
@.str.28 = [8 x i8] c"~ICANON\00"
@.str.30 = [4 x i8] c"can\00"
@.str.32 = [20 x i8] c"read %d characters\0A\00"
@.str.33 = [6 x i8] c"%02x \00"
@str = [21 x i8] c"Using canonical mode\00"
@str.35 = [19 x i8] c"Args are (can|raw)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca %struct.termios
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.termios* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 24)
%8 = load i32*, i32** inttoptr (i64 16 to i32**)
%9 = ptrtoint i32* %8 to i64
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @tcgetattr(i32 0, %struct.termios* %4)
%13 = icmp slt i32 %12, 0
br i1 %13, label %101, label %14
14: ; preds = %2
%15 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @ICRNL
%18 = and i32 %17, %16
%19 = icmp eq i32 %18, 0
%20 = select i1 %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%21 = load i32, i32* @INLCR
%22 = and i32 %21, %16
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%25 = load i32, i32* @IUCLC
%26 = and i32 %25, %16
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0)
%29 = load i32, i32* @IXON
%30 = and i32 %29, %16
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0)
%33 = select i1 %31, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %20, i8* %24, i8* %28, i8* %32, i8* %33)
%35 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 1
%36 = load i32, i32* %35
%37 = load i32, i32* @ONLRET
%38 = and i32 %37, %36
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0)
%41 = load i32, i32* @OCRNL
%42 = and i32 %41, %36
%43 = icmp eq i32 %42, 0
%44 = select i1 %43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.16, i64 0, i64 0)
%45 = load i32, i32* @ONLCR
%46 = and i32 %45, %36
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.19, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.18, i64 0, i64 0)
%49 = load i32, i32* @OLCUC
%50 = and i32 %49, %36
%51 = icmp eq i32 %50, 0
%52 = select i1 %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.21, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.20, i64 0, i64 0)
%53 = load i32, i32* @OPOST
%54 = and i32 %53, %36
%55 = icmp eq i32 %54, 0
%56 = select i1 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.23, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.22, i64 0, i64 0)
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.13, i64 0, i64 0), i32 %36, i8* %40, i8* %44, i8* %48, i8* %52, i8* %56)
%58 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 2
%59 = load i32, i32* %58
%60 = load i32, i32* @ECHO
%61 = and i32 %60, %59
%62 = icmp eq i32 %61, 0
%63 = select i1 %62, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.26, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.25, i64 0, i64 0)
%64 = load i32, i32* @ICANON
%65 = and i32 %64, %59
%66 = icmp eq i32 %65, 0
%67 = select i1 %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.28, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.27, i64 0, i64 0)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.24, i64 0, i64 0), i32 %59, i8* %63, i8* %67)
%69 = icmp slt i32 %0, 2
br i1 %69, label %70, label %72
70: ; preds = %14
%71 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.35, i64 0, i64 0))
br label %101
72: ; preds = %14
%73 = getelementptr inbounds i8*, i8** %1, i64 1
%74 = load i8*, i8** %73
%75 = call i32 @strcmp(i8* dereferenceable(1) %74, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.30, i64 0, i64 0))
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %79
79: ; preds = %72, %77
%80 = call i32 @read(i32 0, i8* %5, i32 256)
%81 = icmp sgt i32 %80, 0
br i1 %81, label %84, label %82
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.32, i64 0, i64 0), i32 %80)
br label %98
84: ; preds = %79
%85 = call i32 @write(i32 1, i8* %5, i32 %80)
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.32, i64 0, i64 0), i32 %85)
%87 = icmp sgt i32 %85, 0
br i1 %87, label %88, label %98
88: ; preds = %84
%89 = zext i32 %85 to i64
br label %90
90: ; preds = %88, %90
%91 = phi i64 [ 0, %88 ], [ %96, %90 ]
%92 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.33, i64 0, i64 0), i32 %94)
%96 = add nuw nsw i64 %91, 1
%97 = icmp eq i64 %96, %89
br i1 %97, label %98, label %90
98: ; preds = %90, %82, %84
%99 = call i32 @putchar(i32 10)
%100 = call i32 @tcsetattr(i32 0, i32 0, %struct.termios* %4)
br label %101
101: ; preds = %2, %98, %70
%102 = phi i32 [ 1, %70 ], [ 0, %98 ], [ 1, %2 ]
ret i32 %102
}