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

/* Variables and functions */
int /*<<< orphan*/ B9600;
int BRKINT;
int CLOCAL;
int CREAD;
int CS8;
int CSIZE;
int CSTOPB;
int ECHO;
int ECHOE;
int ICANON;
int ICRNL;
int IGNBRK;
int IGNCR;
int INLCR;
int ISIG;
int ISTRIP;
int IXON;
int /*<<< orphan*/ OPOST;
int PARENB;
int PARMRK;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int getDebug();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void setup_port(int *fd) {
  struct termios options;
  if (getDebug() > 1)
    printf("I: Port setting: ");
  tcgetattr(*fd, &options);
  cfsetispeed(&options, B9600);
  cfsetospeed(&options, B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  options.c_cflag &= ~(PARENB | CSTOPB | CSIZE);
  options.c_cflag |= CS8;
  options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
  options.c_iflag &=
      ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
  options.c_oflag &= ~OPOST;
  options.c_cc[VMIN] = 0;
  options.c_cc[VTIME] = 1;
  tcsetattr(*fd, TCSANOW, &options);
  if (getDebug() > 1)
    puts("OK");
}


x86 assembly (clang, -O0):
<setup_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <getDebug@plt>
cmp    $0x1,%eax
jle    1198 <setup_port+0x28>
lea    0xe6d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1090 <cfsetispeed@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    0x2da5(%rip),%rcx
or     (%rcx),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2d3d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6c(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
or     -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2d82(%rip),%rcx
or     (%rcx),%eax
mov    0x2d71(%rip),%rcx
or     (%rcx),%eax
mov    0x2d60(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    0x2d35(%rip),%rcx
or     (%rcx),%eax
mov    0x2d94(%rip),%rcx
or     (%rcx),%eax
mov    0x2cf3(%rip),%rcx
or     (%rcx),%eax
mov    0x2d6a(%rip),%rcx
or     (%rcx),%eax
mov    0x2d59(%rip),%rcx
or     (%rcx),%eax
mov    0x2d60(%rip),%rcx
or     (%rcx),%eax
mov    0x2d37(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2cbf(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2c82(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2cd3(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1080 <tcsetattr@plt>
mov    $0x0,%al
call   1060 <getDebug@plt>
cmp    $0x1,%eax
jle    1304 <setup_port+0x194>
lea    0xd13(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_port>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r15
xor    %eax,%eax
call   1060 <getDebug@plt>
cmp    $0x2,%eax
jl     1194 <setup_port+0x24>
lea    0xe71(%rip),%rdi
call   1050 <printf@plt>
mov    (%r15),%edi
mov    %rsp,%r14
mov    %r14,%rsi
call   1070 <tcgetattr@plt>
mov    0x2de7(%rip),%rbx
mov    (%rbx),%esi
mov    %r14,%rdi
call   1090 <cfsetispeed@plt>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1040 <cfsetospeed@plt>
mov    0x2d64(%rip),%rax
mov    0x2db5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
or     (%rsp),%ecx
mov    0x2ddf(%rip),%rax
mov    0x2d50(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2d7d(%rip),%rax
or     (%rax),%edx
not    %edx
and    %ecx,%edx
mov    0x2d80(%rip),%rax
or     (%rax),%edx
mov    0x2d3f(%rip),%rax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %edx,(%rsp)
mov    0x2d8a(%rip),%rax
or     (%rax),%ecx
mov    0x2d79(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x4(%rsp)
mov    0x2d22(%rip),%rax
mov    0x2d53(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2db0(%rip),%rax
or     (%rax),%ecx
mov    0x2d0f(%rip),%rax
or     (%rax),%ecx
mov    0x2d86(%rip),%rax
or     (%rax),%ecx
mov    0x2d75(%rip),%rax
or     (%rax),%ecx
mov    0x2d7c(%rip),%rax
or     (%rax),%ecx
mov    0x2d53(%rip),%rax
or     (%rax),%ecx
not    %ecx
and    %ecx,0x8(%rsp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x18(%rsp)
mov    0x10(%rsp),%rax
mov    0x2ce0(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2ca7(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    (%r15),%edi
mov    0x2cfb(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdx
call   1080 <tcsetattr@plt>
xor    %eax,%eax
call   1060 <getDebug@plt>
cmp    $0x2,%eax
jl     12d7 <setup_port+0x167>
lea    0xd40(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [18 x i8] c"I: Port setting: \00"
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [3 x i8] c"OK\00"
define void @setup_port(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.termios
store i32* %0, i32** %2
%4 = call i32 (...) @getDebug()
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32*, i32** %2
%10 = load i32, i32* %9
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %3)
%12 = load i32, i32* @B9600
%13 = call i32 @cfsetispeed(%struct.termios* %3, i32 %12)
%14 = load i32, i32* @B9600
%15 = call i32 @cfsetospeed(%struct.termios* %3, i32 %14)
%16 = load i32, i32* @CLOCAL
%17 = load i32, i32* @CREAD
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = or i32 %20, %18
store i32 %21, i32* %19
%22 = load i32, i32* @PARENB
%23 = load i32, i32* @CSTOPB
%24 = or i32 %22, %23
%25 = load i32, i32* @CSIZE
%26 = or i32 %24, %25
%27 = xor i32 %26, -1
%28 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, %27
store i32 %30, i32* %28
%31 = load i32, i32* @CS8
%32 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
%33 = load i32, i32* %32
%34 = or i32 %33, %31
store i32 %34, i32* %32
%35 = load i32, i32* @ICANON
%36 = load i32, i32* @ECHO
%37 = or i32 %35, %36
%38 = load i32, i32* @ECHOE
%39 = or i32 %37, %38
%40 = load i32, i32* @ISIG
%41 = or i32 %39, %40
%42 = xor i32 %41, -1
%43 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
%44 = load i32, i32* %43
%45 = and i32 %44, %42
store i32 %45, i32* %43
%46 = load i32, i32* @IGNBRK
%47 = load i32, i32* @BRKINT
%48 = or i32 %46, %47
%49 = load i32, i32* @PARMRK
%50 = or i32 %48, %49
%51 = load i32, i32* @ISTRIP
%52 = or i32 %50, %51
%53 = load i32, i32* @INLCR
%54 = or i32 %52, %53
%55 = load i32, i32* @IGNCR
%56 = or i32 %54, %55
%57 = load i32, i32* @ICRNL
%58 = or i32 %56, %57
%59 = load i32, i32* @IXON
%60 = or i32 %58, %59
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = load i32, i32* @OPOST
%66 = xor i32 %65, -1
%67 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 4
%68 = load i32, i32* %67
%69 = and i32 %68, %66
store i32 %69, i32* %67
%70 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%71 = load i32*, i32** %70
%72 = load i64, i64* @VMIN
%73 = getelementptr inbounds i32, i32* %71, i64 %72
store i32 0, i32* %73
%74 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
%75 = load i32*, i32** %74
%76 = load i64, i64* @VTIME
%77 = getelementptr inbounds i32, i32* %75, i64 %76
store i32 1, i32* %77
%78 = load i32*, i32** %2
%79 = load i32, i32* %78
%80 = load i32, i32* @TCSANOW
%81 = call i32 @tcsetattr(i32 %79, i32 %80, %struct.termios* %3)
%82 = call i32 (...) @getDebug()
%83 = icmp sgt i32 %82, 1
br i1 %83, label %84, label %86
84: ; preds = %8
%85 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %86
86: ; preds = %84, %8
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i32, i32*, i32 }
@.str = [18 x i8] c"I: Port setting: \00"
@B9600 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@CSTOPB = global i32 0
@CSIZE = global i32 0
@CS8 = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@ECHOE = global i32 0
@ISIG = global i32 0
@IGNBRK = global i32 0
@BRKINT = global i32 0
@PARMRK = global i32 0
@ISTRIP = global i32 0
@INLCR = global i32 0
@IGNCR = global i32 0
@ICRNL = global i32 0
@IXON = global i32 0
@OPOST = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [3 x i8] c"OK\00"
define void @setup_port(i32* nocapture %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = tail call i32 (...) @getDebug()
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %0
%10 = call i32 @tcgetattr(i32 %9, %struct.termios* %2)
%11 = load i32, i32* @B9600
%12 = call i32 @cfsetispeed(%struct.termios* %2, i32 %11)
%13 = load i32, i32* @B9600
%14 = call i32 @cfsetospeed(%struct.termios* %2, i32 %13)
%15 = load i32, i32* @CLOCAL
%16 = load i32, i32* @CREAD
%17 = or i32 %16, %15
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%19 = load i32, i32* %18
%20 = or i32 %17, %19
%21 = load i32, i32* @PARENB
%22 = load i32, i32* @CSTOPB
%23 = or i32 %22, %21
%24 = load i32, i32* @CSIZE
%25 = or i32 %23, %24
%26 = xor i32 %25, -1
%27 = and i32 %20, %26
%28 = load i32, i32* @CS8
%29 = or i32 %27, %28
store i32 %29, i32* %18
%30 = load i32, i32* @ICANON
%31 = load i32, i32* @ECHO
%32 = or i32 %31, %30
%33 = load i32, i32* @ECHOE
%34 = or i32 %32, %33
%35 = load i32, i32* @ISIG
%36 = or i32 %34, %35
%37 = xor i32 %36, -1
%38 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%39 = load i32, i32* %38
%40 = and i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* @IGNBRK
%42 = load i32, i32* @BRKINT
%43 = or i32 %42, %41
%44 = load i32, i32* @PARMRK
%45 = or i32 %43, %44
%46 = load i32, i32* @ISTRIP
%47 = or i32 %45, %46
%48 = load i32, i32* @INLCR
%49 = or i32 %47, %48
%50 = load i32, i32* @IGNCR
%51 = or i32 %49, %50
%52 = load i32, i32* @ICRNL
%53 = or i32 %51, %52
%54 = load i32, i32* @IXON
%55 = or i32 %53, %54
%56 = xor i32 %55, -1
%57 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%58 = load i32, i32* %57
%59 = and i32 %58, %56
store i32 %59, i32* %57
%60 = load i32, i32* @OPOST
%61 = xor i32 %60, -1
%62 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 4
%63 = load i32, i32* %62
%64 = and i32 %63, %61
store i32 %64, i32* %62
%65 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%66 = load i32*, i32** %65
%67 = load i64, i64* @VMIN
%68 = getelementptr inbounds i32, i32* %66, i64 %67
store i32 0, i32* %68
%69 = load i64, i64* @VTIME
%70 = getelementptr inbounds i32, i32* %66, i64 %69
store i32 1, i32* %70
%71 = load i32, i32* %0
%72 = load i32, i32* @TCSANOW
%73 = call i32 @tcsetattr(i32 %71, i32 %72, %struct.termios* %2)
%74 = call i32 (...) @getDebug()
%75 = icmp sgt i32 %74, 1
br i1 %75, label %76, label %78
76: ; preds = %8
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %78
78: ; preds = %76, %8
ret void
}