#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 serial_struct {
  scalar_t__ custom_divisor;
  int /*<<< orphan*/ flags;
};

/* Variables and functions */
int /*<<< orphan*/ ASYNC_LOW_LATENCY;
int /*<<< orphan*/ TIOCGSERIAL;
int /*<<< orphan*/ TIOCSSERIAL;
int errno;
int ioctl(int, int /*<<< orphan*/, struct serial_struct *);
int osmo_serial_clear_custom_baudrate(int fd) {
  int rc;
  struct serial_struct ser_info;
  rc = ioctl(fd, TIOCGSERIAL, &ser_info);
  if (rc < 0) {
    do {
    } while (0);
    return -errno;
  }
  ser_info.flags = ASYNC_LOW_LATENCY;
  ser_info.custom_divisor = 0;
  rc = ioctl(fd, TIOCSSERIAL, &ser_info);
  if (rc < 0) {
    do {
    } while (0);
    return -errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<osmo_serial_clear_custom_baudrate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115a <osmo_serial_clear_custom_baudrate+0x4a>
jmp    1142 <osmo_serial_clear_custom_baudrate+0x32>
jmp    1147 <osmo_serial_clear_custom_baudrate+0x37>
xor    %eax,%eax
mov    0x2e80(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <osmo_serial_clear_custom_baudrate+0xa4>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ad <osmo_serial_clear_custom_baudrate+0x9d>
jmp    1195 <osmo_serial_clear_custom_baudrate+0x85>
jmp    119a <osmo_serial_clear_custom_baudrate+0x8a>
xor    %eax,%eax
mov    0x2e2d(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <osmo_serial_clear_custom_baudrate+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osmo_serial_clear_custom_baudrate>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     115c <osmo_serial_clear_custom_baudrate+0x4c>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jns    1167 <osmo_serial_clear_custom_baudrate+0x57>
mov    0x2e6d(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.serial_struct = type { i64, i32 }
@TIOCGSERIAL = global i32 0
@errno = global i32 0
@ASYNC_LOW_LATENCY = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @osmo_serial_clear_custom_baudrate(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.serial_struct
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* @TIOCGSERIAL
%8 = call i32 @ioctl(i32 %6, i32 %7, %struct.serial_struct* %5)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
br label %12
12: ; preds = %11
br label %13
13: ; preds = %12
%14 = load i32, i32* @errno
%15 = sub nsw i32 0, %14
store i32 %15, i32* %2
br label %31
16: ; preds = %1
%17 = load i32, i32* @ASYNC_LOW_LATENCY
%18 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %5, i32 0, i32 1
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %5, i32 0, i32 0
store i64 0, i64* %19
%20 = load i32, i32* %3
%21 = load i32, i32* @TIOCSSERIAL
%22 = call i32 @ioctl(i32 %20, i32 %21, %struct.serial_struct* %5)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %16
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26
%28 = load i32, i32* @errno
%29 = sub nsw i32 0, %28
store i32 %29, i32* %2
br label %31
30: ; preds = %16
store i32 0, i32* %2
br label %31
31: ; preds = %30, %27, %13
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
%struct.serial_struct = type { i64, i32 }
@TIOCGSERIAL = global i32 0
@errno = global i32 0
@ASYNC_LOW_LATENCY = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @osmo_serial_clear_custom_baudrate(i32 %0) {
%2 = alloca %struct.serial_struct
%3 = bitcast %struct.serial_struct* %2 to i8*
%4 = load i32, i32* @TIOCGSERIAL
%5 = call i32 @ioctl(i32 %0, i32 %4, %struct.serial_struct* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = sub nsw i32 0, %8
br label %20
10: ; preds = %1
%11 = load i32, i32* @ASYNC_LOW_LATENCY
%12 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %2, i64 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %2, i64 0, i32 0
store i64 0, i64* %13
%14 = load i32, i32* @TIOCSSERIAL
%15 = call i32 @ioctl(i32 %0, i32 %14, %struct.serial_struct* %2)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i32, i32* @errno
%19 = sub nsw i32 0, %18
br label %20
20: ; preds = %10, %17, %7
%21 = phi i32 [ %9, %7 ], [ %19, %17 ], [ 0, %10 ]
ret i32 %21
}