#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ B38400;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TCIOFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetispeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ cfsetospeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int setup_modem() {
  struct termios attr;
  int fildes;
  if ((fildes = open("/dev/tty0", O_RDWR)) == -1) {
    perror("device open failed");
    exit(1);
  }
  tcgetattr(fildes, &attr);
  cfsetispeed(&attr, B38400);
  cfsetospeed(&attr, B38400);
  tcflush(fildes, TCIOFLUSH);
  tcsetattr(fildes, TCSANOW, &attr);
  return fildes;
}


x86 assembly (clang, -O0):
<setup_modem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe68(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11bf <setup_modem+0x3f>
lea    0xe5a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1080 <cfsetispeed@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
call   1030 <cfsetospeed@plt>
mov    -0xc(%rbp),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
mov    -0xc(%rbp),%edi
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1060 <tcsetattr@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_modem>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1200 <setup_modem+0x80>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e05(%rip),%r15
mov    (%r15),%esi
mov    %r14,%rdi
call   1080 <cfsetispeed@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <cfsetospeed@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe03(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [10 x i8] c"/dev/tty0\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"device open failed\00"
@B38400 = global i32 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @setup_modem() {
%1 = alloca %struct.termios
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @tcgetattr(i32 %10, %struct.termios* %1)
%12 = load i32, i32* @B38400
%13 = call i32 @cfsetispeed(%struct.termios* %1, i32 %12)
%14 = load i32, i32* @B38400
%15 = call i32 @cfsetospeed(%struct.termios* %1, i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* @TCIOFLUSH
%18 = call i32 @tcflush(i32 %16, i32 %17)
%19 = load i32, i32* %2
%20 = load i32, i32* @TCSANOW
%21 = call i32 @tcsetattr(i32 %19, i32 %20, %struct.termios* %1)
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [10 x i8] c"/dev/tty0\00"
@O_RDWR = global i32 0
@.str.1 = [19 x i8] c"device open failed\00"
@B38400 = global i32 0
@TCIOFLUSH = global i32 0
@TCSANOW = global i32 0
define i32 @setup_modem() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @tcgetattr(i32 %4, %struct.termios* %1)
%11 = load i32, i32* @B38400
%12 = call i32 @cfsetispeed(%struct.termios* %1, i32 %11)
%13 = load i32, i32* @B38400
%14 = call i32 @cfsetospeed(%struct.termios* %1, i32 %13)
%15 = load i32, i32* @TCIOFLUSH
%16 = call i32 @tcflush(i32 %4, i32 %15)
%17 = load i32, i32* @TCSANOW
%18 = call i32 @tcsetattr(i32 %4, i32 %17, %struct.termios* %1)
ret i32 %4
}