#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 */

/* Variables and functions */
int TIOCMBIC;
int TIOCMBIS;
int errno;
scalar_t__ ioctl(int, int, int *);
int /*<<< orphan*/ message(char *, char *, int, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ serial_errcode();
int /*<<< orphan*/ serial_errmsg();
int serial_set_status(int fd, int value, int level) {
  int action = (level ? TIOCMBIS : TIOCMBIC);
  if (ioctl(fd, action, &value) != 0) {
    {
      int error = errno;
      message("TRACE (%s:%d, %s): %s (%d)\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/andysan/libdivecomputer/refs/heads/"
              "master/src/serial_posix.c",
              613, "ioctl", serial_errmsg(), serial_errcode());
      errno = error;
    };
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<serial_set_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     116c <serial_set_status+0x2c>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <serial_set_status+0x38>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0xc(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     11f2 <serial_set_status+0xb2>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <serial_errmsg@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <serial_errcode@plt>
mov    -0x20(%rbp),%r8d
mov    %eax,%r9d
lea    0xe3e(%rip),%rdi
lea    0xe53(%rip),%rsi
mov    $0x265,%edx
lea    0xede(%rip),%rcx
call   1030 <message@plt>
mov    -0x18(%rbp),%ecx
mov    0x2dec(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <serial_set_status+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_set_status>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,0xc(%rsp)
test   %edx,%edx
jne    1159 <serial_set_status+0x19>
mov    0x2e81(%rip),%rax
jmp    1160 <serial_set_status+0x20>
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
je     11ba <serial_set_status+0x7a>
mov    0x2e58(%rip),%r14
mov    (%r14),%ebp
xor    %eax,%eax
call   1040 <serial_errmsg@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <serial_errcode@plt>
lea    0xe6e(%rip),%rdi
lea    0xe83(%rip),%rsi
lea    0xf13(%rip),%rcx
mov    $0x265,%edx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1030 <message@plt>
mov    %ebp,(%r14)
mov    $0xffffffff,%eax
jmp    11bc <serial_set_status+0x7c>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
@errno = global i32 0
@.str = [28 x i8] c"TRACE (%s:%d, %s): %s (%d)\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/libdivecomputer/refs/heads/master/src/serial_posix.c\00"
@.str.2 = [6 x i8] c"ioctl\00"
define i32 @serial_set_status(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i32, i32* @TIOCMBIS
br label %16
14: ; preds = %3
%15 = load i32, i32* @TIOCMBIC
br label %16
16: ; preds = %14, %12
%17 = phi i32 [ %13, %12 ], [ %15, %14 ]
store i32 %17, i32* %8
%18 = load i32, i32* %5
%19 = load i32, i32* %8
%20 = call i64 @ioctl(i32 %18, i32 %19, i32* %6)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i32, i32* @errno
store i32 %23, i32* %9
%24 = call i32 (...) @serial_errmsg()
%25 = call i32 (...) @serial_errcode()
%26 = call i32 @message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 613, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25)
%27 = load i32, i32* %9
store i32 %27, i32* @errno
store i32 -1, i32* %4
br label %29
28: ; preds = %16
store i32 0, i32* %4
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
@errno = global i32 0
@.str = [28 x i8] c"TRACE (%s:%d, %s): %s (%d)\0A\00"
@.str.1 = [151 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/andysan/libdivecomputer/refs/heads/master/src/serial_posix.c\00"
@.str.2 = [6 x i8] c"ioctl\00"
define i32 @serial_set_status(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
store i32 %1, i32* %4
%5 = icmp eq i32 %2, 0
%6 = load i32, i32* @TIOCMBIS
%7 = load i32, i32* @TIOCMBIC
%8 = select i1 %5, i32 %7, i32 %6
%9 = call i64 @ioctl(i32 %0, i32 %8, i32* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i32, i32* @errno
%13 = call i32 (...) @serial_errmsg()
%14 = call i32 (...) @serial_errcode()
%15 = call i32 @message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([151 x i8], [151 x i8]* @.str.1, i64 0, i64 0), i32 613, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
store i32 %12, i32* @errno
br label %16
16: ; preds = %3, %11
%17 = phi i32 [ -1, %11 ], [ 0, %3 ]
ret i32 %17
}