#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 {
  unsigned int c_cflag;
  int c_iflag;
  scalar_t__ c_lflag;
  scalar_t__ c_oflag;
};

/* Variables and functions */
unsigned int CLOCAL;
unsigned int CREAD;
unsigned int CS8;
int IGNBRK;
int IGNPAR;
unsigned int NOFLSH;
int /*<<< orphan*/ TCIFLUSH;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ print_debug(int, char *, char *, int, char *, unsigned int);
int /*<<< orphan*/ print_error(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
scalar_t__ tcflush(int, int /*<<< orphan*/);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int serial_set(int serial_fd, unsigned int baudrate) {
  struct termios options;
  print_debug(3, "comm",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/susundberg/Geotech_tool/refs/heads/"
              "master/src/serial.c",
              433, "   set serial device baud %d ", baudrate);
  tcgetattr(serial_fd, &options);
  options.c_cflag = baudrate | CS8 | CLOCAL | CREAD | NOFLSH;
  options.c_iflag = IGNPAR | IGNBRK;
  options.c_oflag = 0;
  options.c_lflag = 0;
  if (tcsetattr(serial_fd, TCSANOW, &options) != 0) {
    print_error("comm", " Command tcsetattr failed: %s ", strerror(errno));
    return -1;
  }
  if (tcflush(serial_fd, TCIFLUSH) != 0) {
    print_error("comm", " Command tcflush failed: %s ", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<serial_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%r9d
mov    $0x3,%edi
lea    0xe82(%rip),%rsi
lea    0xe80(%rip),%rdx
mov    $0x1b1,%ecx
lea    0xf05(%rip),%r8
call   1070 <print_debug@plt>
mov    -0x8(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1050 <tcgetattr@plt>
mov    -0xc(%rbp),%eax
mov    0x2e2c(%rip),%rcx
or     (%rcx),%eax
mov    0x2de3(%rip),%rcx
or     (%rcx),%eax
mov    0x2e22(%rip),%rcx
or     (%rcx),%eax
mov    0x2e09(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    0x2dd4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1060 <tcsetattr@plt>
cmp    $0x0,%rax
je     123f <serial_set+0xdf>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%edx
lea    0xdd9(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <serial_set+0x130>
mov    -0x8(%rbp),%edi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
call   1040 <tcflush@plt>
cmp    $0x0,%rax
je     1289 <serial_set+0x129>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    %eax,%edx
lea    0xd8f(%rip),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1290 <serial_set+0x130>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_set>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xe8d(%rip),%rsi
lea    0xe8b(%rip),%rdx
lea    0xf15(%rip),%r8
mov    $0x3,%edi
mov    $0x1b1,%ecx
mov    %ebp,%r9d
call   1070 <print_debug@plt>
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e2f(%rip),%rax
or     (%rax),%ebp
mov    0x2de6(%rip),%rax
or     (%rax),%ebp
mov    0x2e25(%rip),%rax
or     (%rax),%ebp
mov    0x2e0c(%rip),%rax
or     (%rax),%ebp
mov    %ebp,0x8(%rsp)
mov    0x2dd7(%rip),%rax
mov    0x2dd8(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rsp)
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %rax,%rax
je     1209 <serial_set+0xa9>
lea    0xead(%rip),%rbx
jmp    1225 <serial_set+0xc5>
mov    0x2db0(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <tcflush@plt>
test   %rax,%rax
je     1252 <serial_set+0xf2>
lea    0xeae(%rip),%rbx
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xdc6(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <print_error@plt>
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    1249 <serial_set+0xe9>

LLVM IR (-O0):
%struct.termios = type { i32, i32, i64, i64 }
@.str = [5 x i8] c"comm\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/susundberg/Geotech_tool/refs/heads/master/src/serial.c\00"
@.str.2 = [30 x i8] c" set serial device baud %d \00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@NOFLSH = global i32 0
@IGNPAR = global i32 0
@IGNBRK = global i32 0
@TCSANOW = global i32 0
@.str.3 = [31 x i8] c" Command tcsetattr failed: %s \00"
@errno = global i32 0
@TCIFLUSH = global i32 0
@.str.4 = [29 x i8] c" Command tcflush failed: %s \00"
define i32 @serial_set(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = call i32 @print_debug(i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 433, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %4
%10 = call i32 @tcgetattr(i32 %9, %struct.termios* %6)
%11 = load i32, i32* %5
%12 = load i32, i32* @CS8
%13 = or i32 %11, %12
%14 = load i32, i32* @CLOCAL
%15 = or i32 %13, %14
%16 = load i32, i32* @CREAD
%17 = or i32 %15, %16
%18 = load i32, i32* @NOFLSH
%19 = or i32 %17, %18
%20 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @IGNPAR
%22 = load i32, i32* @IGNBRK
%23 = or i32 %21, %22
%24 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 3
store i64 0, i64* %25
%26 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 2
store i64 0, i64* %26
%27 = load i32, i32* %4
%28 = load i32, i32* @TCSANOW
%29 = call i64 @tcsetattr(i32 %27, i32 %28, %struct.termios* %6)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %2
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 @print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 -1, i32* %3
br label %45
35: ; preds = %2
%36 = load i32, i32* %4
%37 = load i32, i32* @TCIFLUSH
%38 = call i64 @tcflush(i32 %36, i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 @print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %42)
store i32 -1, i32* %3
br label %45
44: ; preds = %35
store i32 0, i32* %3
br label %45
45: ; preds = %44, %40, %31
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.termios = type { i32, i32, i64, i64 }
@.str = [5 x i8] c"comm\00"
@.str.1 = [145 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/susundberg/Geotech_tool/refs/heads/master/src/serial.c\00"
@.str.2 = [30 x i8] c" set serial device baud %d \00"
@CS8 = global i32 0
@CLOCAL = global i32 0
@CREAD = global i32 0
@NOFLSH = global i32 0
@IGNPAR = global i32 0
@IGNBRK = global i32 0
@TCSANOW = global i32 0
@.str.3 = [31 x i8] c" Command tcsetattr failed: %s \00"
@errno = global i32 0
@TCIFLUSH = global i32 0
@.str.4 = [29 x i8] c" Command tcflush failed: %s \00"
define i32 @serial_set(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = tail call i32 @print_debug(i32 3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([145 x i8], [145 x i8]* @.str.1, i64 0, i64 0), i32 433, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%6 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%7 = load i32, i32* @CS8
%8 = or i32 %7, %1
%9 = load i32, i32* @CLOCAL
%10 = or i32 %8, %9
%11 = load i32, i32* @CREAD
%12 = or i32 %10, %11
%13 = load i32, i32* @NOFLSH
%14 = or i32 %12, %13
%15 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @IGNPAR
%17 = load i32, i32* @IGNBRK
%18 = or i32 %17, %16
%19 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 2
%21 = bitcast i64* %20 to i8*
%22 = load i32, i32* @TCSANOW
%23 = call i64 @tcsetattr(i32 %0, i32 %22, %struct.termios* %3)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i32, i32* @TCIFLUSH
%27 = call i64 @tcflush(i32 %0, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25, %2
%30 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %2 ], [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), %25 ]
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 @print_error(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %30, i32 %32)
br label %34
34: ; preds = %29, %25
%35 = phi i32 [ 0, %25 ], [ -1, %29 ]
ret i32 %35
}