#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 {
  char *c_cc;
  int c_iflag;
  int c_cflag;
  int /*<<< orphan*/ c_lflag;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int CBAUD;
int CLOCAL;
int CREAD;
int CRTSCTS;
int HUPCL;
int IGNBRK;
int IGNPAR;
int NCCS;
size_t VMIN;
size_t VTIME;
int tty_set_raw(struct termios *tty) {
  int i;
  int speed;
  for (i = 0; i < NCCS; i++)
    tty->c_cc[i] = '\0';
  tty->c_cc[VMIN] = 1;
  tty->c_cc[VTIME] = 0;
  tty->c_iflag = (IGNBRK | IGNPAR);
  tty->c_oflag = (0);
  tty->c_lflag = (0);
  speed = (tty->c_cflag & CBAUD);
  tty->c_cflag = (CRTSCTS | HUPCL | CREAD);
  tty->c_cflag |= CLOCAL;
  tty->c_cflag |= speed;
  return 0;
}


x86 assembly (clang, -O0):
<tty_set_raw>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ed7(%rip),%rcx
cmp    (%rcx),%eax
jge    113e <tty_set_raw+0x3e>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    110f <tty_set_raw+0xf>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
mov    0x2e38(%rip),%rax
or     (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x14(%rax)
mov    -0x8(%rbp),%rax
movl   $0x0,0x10(%rax)
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%eax
mov    0x2dfb(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%ecx
mov    0x2dfe(%rip),%rax
or     (%rax),%ecx
mov    0x2e1d(%rip),%rax
or     (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
or     0xc(%rax),%ecx
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
or     0xc(%rax),%ecx
mov    %ecx,0xc(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_set_raw>:
mov    0x2ee9(%rip),%rax
cmpl   $0x0,(%rax)
jle    1123 <tty_set_raw+0x23>
xor    %ecx,%ecx
xchg   %ax,%ax
mov    (%rdi),%rdx
movb   $0x0,(%rdx,%rcx,1)
add    $0x1,%rcx
movslq (%rax),%rdx
cmp    %rdx,%rcx
jl     1110 <tty_set_raw+0x10>
mov    (%rdi),%rax
mov    0x2eab(%rip),%rcx
mov    (%rcx),%rcx
movb   $0x1,(%rax,%rcx,1)
mov    (%rdi),%rax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2e7c(%rip),%rax
mov    0x2e5d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x8(%rdi)
movq   $0x0,0x10(%rdi)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
and    0xc(%rdi),%eax
mov    0x2e23(%rip),%rcx
mov    0x2e3c(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2e59(%rip),%rcx
or     (%rcx),%edx
or     %eax,%edx
mov    0x2dfe(%rip),%rax
or     (%rax),%edx
mov    %edx,0xc(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.termios = type { i8*, i32, i32, i32, i32 }
@NCCS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@CBAUD = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
define i32 @tty_set_raw(%struct.termios* %0) {
%2 = alloca %struct.termios*
%3 = alloca i32
%4 = alloca i32
store %struct.termios* %0, %struct.termios** %2
store i32 0, i32* %3
br label %5
5: ; preds = %16, %1
%6 = load i32, i32* %3
%7 = load i32, i32* @NCCS
%8 = icmp slt i32 %6, %7
br i1 %8, label %9, label %19
9: ; preds = %5
%10 = load %struct.termios*, %struct.termios** %2
%11 = getelementptr inbounds %struct.termios, %struct.termios* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %9
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %5
19: ; preds = %5
%20 = load %struct.termios*, %struct.termios** %2
%21 = getelementptr inbounds %struct.termios, %struct.termios* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = load i64, i64* @VMIN
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8 1, i8* %24
%25 = load %struct.termios*, %struct.termios** %2
%26 = getelementptr inbounds %struct.termios, %struct.termios* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = load i64, i64* @VTIME
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 0, i8* %29
%30 = load i32, i32* @IGNBRK
%31 = load i32, i32* @IGNPAR
%32 = or i32 %30, %31
%33 = load %struct.termios*, %struct.termios** %2
%34 = getelementptr inbounds %struct.termios, %struct.termios* %33, i32 0, i32 1
store i32 %32, i32* %34
%35 = load %struct.termios*, %struct.termios** %2
%36 = getelementptr inbounds %struct.termios, %struct.termios* %35, i32 0, i32 4
store i32 0, i32* %36
%37 = load %struct.termios*, %struct.termios** %2
%38 = getelementptr inbounds %struct.termios, %struct.termios* %37, i32 0, i32 3
store i32 0, i32* %38
%39 = load %struct.termios*, %struct.termios** %2
%40 = getelementptr inbounds %struct.termios, %struct.termios* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = load i32, i32* @CBAUD
%43 = and i32 %41, %42
store i32 %43, i32* %4
%44 = load i32, i32* @CRTSCTS
%45 = load i32, i32* @HUPCL
%46 = or i32 %44, %45
%47 = load i32, i32* @CREAD
%48 = or i32 %46, %47
%49 = load %struct.termios*, %struct.termios** %2
%50 = getelementptr inbounds %struct.termios, %struct.termios* %49, i32 0, i32 2
store i32 %48, i32* %50
%51 = load i32, i32* @CLOCAL
%52 = load %struct.termios*, %struct.termios** %2
%53 = getelementptr inbounds %struct.termios, %struct.termios* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = or i32 %54, %51
store i32 %55, i32* %53
%56 = load i32, i32* %4
%57 = load %struct.termios*, %struct.termios** %2
%58 = getelementptr inbounds %struct.termios, %struct.termios* %57, i32 0, i32 2
%59 = load i32, i32* %58
%60 = or i32 %59, %56
store i32 %60, i32* %58
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i8*, i32, i32, i32, i32 }
@NCCS = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@IGNBRK = global i32 0
@IGNPAR = global i32 0
@CBAUD = global i32 0
@CRTSCTS = global i32 0
@HUPCL = global i32 0
@CREAD = global i32 0
@CLOCAL = global i32 0
define i32 @tty_set_raw(%struct.termios* nocapture %0) {
%2 = load i32, i32* @NCCS
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %1
%5 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %10, %6 ]
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 %7
store i8 0, i8* %9
%10 = add nuw nsw i64 %7, 1
%11 = load i32, i32* @NCCS
%12 = sext i32 %11 to i64
%13 = icmp slt i64 %10, %12
br i1 %13, label %6, label %14
14: ; preds = %6, %1
%15 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = load i64, i64* @VMIN
%18 = getelementptr inbounds i8, i8* %16, i64 %17
store i8 1, i8* %18
%19 = load i8*, i8** %15
%20 = load i64, i64* @VTIME
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 0, i8* %21
%22 = load i32, i32* @IGNBRK
%23 = load i32, i32* @IGNPAR
%24 = or i32 %23, %22
%25 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 4
store i32 0, i32* %26
%27 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 3
store i32 0, i32* %27
%28 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 2
%29 = load i32, i32* %28
%30 = load i32, i32* @CBAUD
%31 = and i32 %30, %29
%32 = load i32, i32* @CRTSCTS
%33 = load i32, i32* @HUPCL
%34 = or i32 %33, %32
%35 = load i32, i32* @CREAD
%36 = or i32 %34, %35
%37 = load i32, i32* @CLOCAL
%38 = or i32 %36, %31
%39 = or i32 %38, %37
store i32 %39, i32* %28
ret i32 0
}