#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_cflag;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
};

/* Variables and functions */
int /*<<< orphan*/ B2400;
int B9600;
int CLOCAL;
int CREAD;
int CS8;
int HUPCL;
int ICRNL;
int IXON;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
int init_port(int fd) {
  struct termios attr;
  if (tcgetattr(fd, &attr))
    return 1;
  cfsetospeed(&attr, B2400);
  cfsetispeed(&attr, B2400);
  attr.c_iflag = IXON | ICRNL;
  attr.c_cflag = CLOCAL | HUPCL | CREAD | B9600 | CS8;
  attr.c_oflag = 0;
  attr.c_lflag = 0;
  return tcsetattr(fd, TCSANOW, &attr);
}


x86 assembly (clang, -O0):
<init_port>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     116d <init_port+0x2d>
movl   $0x1,-0x4(%rbp)
jmp    11fe <init_port+0xbe>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    0x2e47(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    0x2df2(%rip),%rcx
or     (%rcx),%eax
mov    0x2e09(%rip),%rcx
or     (%rcx),%eax
mov    0x2e08(%rip),%rcx
or     (%rcx),%eax
mov    0x2def(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_port>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1040 <tcgetattr@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    11ea <init_port+0xaa>
mov    0x2e43(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1060 <cfsetispeed@plt>
mov    0x2e51(%rip),%rax
mov    0x2e52(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2df7(%rip),%rax
mov    0x2e00(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
mov    0x2e15(%rip),%rax
or     (%rax),%edx
mov    %ecx,0x8(%rsp)
mov    0x2e10(%rip),%rax
or     (%rax),%edx
mov    0x2df7(%rip),%rax
or     (%rax),%edx
mov    %edx,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64, i64 }
@B2400 = global i32 0
@IXON = global i32 0
@ICRNL = global i32 0
@CLOCAL = global i32 0
@HUPCL = global i32 0
@CREAD = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
define i32 @init_port(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.termios
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @tcgetattr(i32 %5, %struct.termios* %4)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %2
br label %33
9: ; preds = %1
%10 = load i32, i32* @B2400
%11 = call i32 @cfsetospeed(%struct.termios* %4, i32 %10)
%12 = load i32, i32* @B2400
%13 = call i32 @cfsetispeed(%struct.termios* %4, i32 %12)
%14 = load i32, i32* @IXON
%15 = load i32, i32* @ICRNL
%16 = or i32 %14, %15
%17 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @CLOCAL
%19 = load i32, i32* @HUPCL
%20 = or i32 %18, %19
%21 = load i32, i32* @CREAD
%22 = or i32 %20, %21
%23 = load i32, i32* @B9600
%24 = or i32 %22, %23
%25 = load i32, i32* @CS8
%26 = or i32 %24, %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 1
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 3
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.termios, %struct.termios* %4, i32 0, i32 2
store i64 0, i64* %29
%30 = load i32, i32* %3
%31 = load i32, i32* @TCSANOW
%32 = call i32 @tcsetattr(i32 %30, i32 %31, %struct.termios* %4)
store i32 %32, i32* %2
br label %33
33: ; preds = %9, %8
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64, i64 }
@B2400 = global i32 0
@IXON = global i32 0
@ICRNL = global i32 0
@CLOCAL = global i32 0
@HUPCL = global i32 0
@CREAD = global i32 0
@B9600 = global i32 0
@CS8 = global i32 0
@TCSANOW = global i32 0
define i32 @init_port(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = call i64 @tcgetattr(i32 %0, %struct.termios* %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = load i32, i32* @B2400
%8 = call i32 @cfsetospeed(%struct.termios* %2, i32 %7)
%9 = load i32, i32* @B2400
%10 = call i32 @cfsetispeed(%struct.termios* %2, i32 %9)
%11 = load i32, i32* @IXON
%12 = load i32, i32* @ICRNL
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @CLOCAL
%16 = load i32, i32* @HUPCL
%17 = or i32 %16, %15
%18 = load i32, i32* @CREAD
%19 = or i32 %17, %18
%20 = load i32, i32* @B9600
%21 = or i32 %19, %20
%22 = load i32, i32* @CS8
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%26 = bitcast i64* %25 to i8*
%27 = load i32, i32* @TCSANOW
%28 = call i32 @tcsetattr(i32 %0, i32 %27, %struct.termios* %2)
br label %29
29: ; preds = %1, %6
%30 = phi i32 [ %28, %6 ], [ 1, %1 ]
ret i32 %30
}