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

/* Variables and functions */
int /*<<< orphan*/ B57600;
int CLOCAL;
int CREAD;
int CS8;
int PARENB;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ cfsetspeed(struct termios *, int /*<<< orphan*/);
int /*<<< orphan*/ die(char *);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void st_termsetup(int fd) {
  struct termios termios;
  if (tcgetattr(fd, &termios) != 0)
    die("can't set termios\n");
  termios.c_iflag = 0;
  termios.c_oflag = 0;
  termios.c_cflag = CS8 | CLOCAL | CREAD | PARENB;
  termios.c_lflag = 0;
  cfsetspeed(&termios, B57600);
  if (tcsetattr(fd, TCSANOW, &termios) != 0)
    die("can't set termios\n");
}


x86 assembly (clang, -O0):
<st_termsetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     116d <st_termsetup+0x2d>
lea    0xe98(%rip),%rdi
call   1060 <die@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    0x2e23(%rip),%rcx
or     (%rcx),%eax
mov    0x2e42(%rip),%rcx
or     (%rcx),%eax
mov    0x2e49(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdi
call   1030 <cfsetspeed@plt>
mov    -0x4(%rbp),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
je     11e9 <st_termsetup+0xa9>
lea    0xe1c(%rip),%rdi
call   1060 <die@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<st_termsetup>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
je     1164 <st_termsetup+0x24>
lea    0xea1(%rip),%rdi
call   1060 <die@plt>
mov    0x2e65(%rip),%rax
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xorps  %xmm0,%xmm0
mov    0x2e58(%rip),%rax
or     (%rax),%ecx
movups %xmm0,0x18(%rsp)
mov    0x2e5a(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1030 <cfsetspeed@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1050 <tcsetattr@plt>
test   %rax,%rax
je     11d7 <st_termsetup+0x97>
lea    0xe2e(%rip),%rdi
call   1060 <die@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32, i64, i64, i64 }
@.str = [19 x i8] c"can't set termios\0A\00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@B57600 = global i32 0
@TCSANOW = global i32 0
define void @st_termsetup(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.termios
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i64 @tcgetattr(i32 %4, %struct.termios* %3)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 3
store i64 0, i64* %10
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 2
store i64 0, i64* %11
%12 = load i32, i32* @CS8
%13 = load i32, i32* @CLOCAL
%14 = or i32 %12, %13
%15 = load i32, i32* @CREAD
%16 = or i32 %14, %15
%17 = load i32, i32* @PARENB
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i32 0, i32 1
store i64 0, i64* %20
%21 = load i32, i32* @B57600
%22 = call i32 @cfsetspeed(%struct.termios* %3, i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* @TCSANOW
%25 = call i64 @tcsetattr(i32 %23, i32 %24, %struct.termios* %3)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %9
%28 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %9
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32, i64, i64, i64 }
@.str = [19 x i8] c"can't set termios\0A\00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@PARENB = global i32 0
@B57600 = global i32 0
@TCSANOW = global i32 0
define void @st_termsetup(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 %8, label %6
6: ; preds = %1
%7 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%10 = bitcast i64* %9 to i8*
%11 = load i32, i32* @CS8
%12 = load i32, i32* @CLOCAL
%13 = or i32 %12, %11
%14 = load i32, i32* @CREAD
%15 = or i32 %13, %14
%16 = load i32, i32* @PARENB
%17 = or i32 %15, %16
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
store i64 0, i64* %19
%20 = load i32, i32* @B57600
%21 = call i32 @cfsetspeed(%struct.termios* %2, i32 %20)
%22 = load i32, i32* @TCSANOW
%23 = call i64 @tcsetattr(i32 %0, i32 %22, %struct.termios* %2)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %8
%26 = call i32 @die(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %8
ret void
}