#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_lflag;
  int /*<<< orphan*/ c_cflag;
  int /*<<< orphan*/ c_oflag;
};

/* Variables and functions */
int /*<<< orphan*/ B19200;
int BRKINT;
int ECHO;
int ICRNL;
int IEXTEN;
int IMAXBEL;
int /*<<< orphan*/ ONLCR;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ printf(char *);
scalar_t__ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int setTemFlagsKathrein(int fd) {
  struct termios old_io;
  struct termios new_io;
  if ((tcgetattr(fd, &old_io)) == 0) {
    new_io = old_io;
    printf("setting new flags\n");
    new_io.c_iflag &= ~(IMAXBEL | BRKINT | ICRNL);
    new_io.c_lflag &= ~(ECHO | IEXTEN);
    new_io.c_oflag &= ~(ONLCR);
    new_io.c_cflag = B19200;
    tcsetattr(fd, TCSANOW, &new_io);
  } else
    printf("error set raw mode.\n");
  return 0;
}


x86 assembly (clang, -O0):
<setTemFlagsKathrein>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
jne    11e4 <setTemFlagsKathrein+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    0x2e4b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e5a(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    0x2e1f(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <tcsetattr@plt>
jmp    11f0 <setTemFlagsKathrein+0xc0>
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setTemFlagsKathrein>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
je     1154 <setTemFlagsKathrein+0x24>
lea    0xeb3(%rip),%rdi
call   1030 <puts@plt>
jmp    11d0 <setTemFlagsKathrein+0xa0>
movups 0x10(%rsp),%xmm0
movaps %xmm0,(%rsp)
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e38(%rip),%rax
mov    0x2e51(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e5e(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    0x2e40(%rip),%rax
mov    0x2e29(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0xc(%rsp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <tcsetattr@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32 }
@.str = [19 x i8] c"setting new flags\0A\00"
@IMAXBEL = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@ECHO = global i32 0
@IEXTEN = global i32 0
@ONLCR = global i32 0
@B19200 = global i32 0
@TCSANOW = global i32 0
@.str.1 = [21 x i8] c"error set raw mode.\0A\00"
define i32 @setTemFlagsKathrein(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
%4 = alloca %struct.termios
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @tcgetattr(i32 %5, %struct.termios* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %38
8: ; preds = %1
%9 = bitcast %struct.termios* %4 to i8*
%10 = bitcast %struct.termios* %3 to i8*
%11 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @IMAXBEL
%13 = load i32, i32* @BRKINT
%14 = or i32 %12, %13
%15 = load i32, i32* @ICRNL
%16 = or i32 %14, %15
%17 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = load i32, i32* @ECHO
%22 = load i32, i32* @IEXTEN
%23 = or i32 %21, %22
%24 = xor i32 %23, -1
%25 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
%26 = load i32, i32* %25
%27 = and i32 %26, %24
store i32 %27, i32* %25
%28 = load i32, i32* @ONLCR
%29 = xor i32 %28, -1
%30 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
%31 = load i32, i32* %30
%32 = and i32 %31, %29
store i32 %32, i32* %30
%33 = load i32, i32* @B19200
%34 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i32, i32* %2
%36 = load i32, i32* @TCSANOW
%37 = call i32 @tcsetattr(i32 %35, i32 %36, %struct.termios* %4)
br label %40
38: ; preds = %1
%39 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %8
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32 }
@IMAXBEL = global i32 0
@BRKINT = global i32 0
@ICRNL = global i32 0
@ECHO = global i32 0
@IEXTEN = global i32 0
@ONLCR = global i32 0
@B19200 = global i32 0
@TCSANOW = global i32 0
@str = [20 x i8] c"error set raw mode.\00"
@str.2 = [18 x i8] c"setting new flags\00"
define i32 @setTemFlagsKathrein(i32 %0) {
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %2 to i8*
%5 = bitcast %struct.termios* %3 to i8*
%6 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %35
8: ; preds = %1
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%10 = load i32, i32* @IMAXBEL
%11 = load i32, i32* @BRKINT
%12 = or i32 %11, %10
%13 = load i32, i32* @ICRNL
%14 = or i32 %12, %13
%15 = xor i32 %14, -1
%16 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = and i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* @ECHO
%20 = load i32, i32* @IEXTEN
%21 = or i32 %20, %19
%22 = xor i32 %21, -1
%23 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%24 = load i32, i32* %23
%25 = and i32 %24, %22
store i32 %25, i32* %23
%26 = load i32, i32* @ONLCR
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 3
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @B19200
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @TCSANOW
%34 = call i32 @tcsetattr(i32 %0, i32 %33, %struct.termios* %3)
br label %37
35: ; preds = %1
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %8
ret i32 0
}