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

/* Variables and functions */
int /*<<< orphan*/ ASYNC_LOW_LATENCY;
int /*<<< orphan*/ TIOCGSERIAL;
int /*<<< orphan*/ TIOCSSERIAL;
int ioctl(int, int /*<<< orphan*/, struct serial_struct *);
int carmen_serial_set_low_latency(int fd) {
  struct serial_struct serial;
  int result;
  result = ioctl(fd, TIOCGSERIAL, &serial);
  if (result) {
    return result;
  } else {
    serial.flags |= ASYNC_LOW_LATENCY;
    serial.xmit_fifo_size = 1;
    ioctl(fd, TIOCSSERIAL, &serial);
    if (result) {
      return result;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<carmen_serial_set_low_latency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1148 <carmen_serial_set_low_latency+0x38>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <carmen_serial_set_low_latency+0x83>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmpl   $0x0,-0x14(%rbp)
je     1188 <carmen_serial_set_low_latency+0x78>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1193 <carmen_serial_set_low_latency+0x83>
jmp    118d <carmen_serial_set_low_latency+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<carmen_serial_set_low_latency>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1153 <carmen_serial_set_low_latency+0x43>
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
or     %eax,0x4(%rsp)
movl   $0x1,(%rsp)
mov    0x2eb1(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.serial_struct = type { i32, i32 }
@TIOCGSERIAL = global i32 0
@ASYNC_LOW_LATENCY = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @carmen_serial_set_low_latency(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.serial_struct
%5 = alloca i32
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* %4)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %5
store i32 %12, i32* %2
br label %29
13: ; preds = %1
%14 = load i32, i32* @ASYNC_LOW_LATENCY
%15 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %4, i32 0, i32 1
%16 = load i32, i32* %15
%17 = or i32 %16, %14
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %4, i32 0, i32 0
store i32 1, i32* %18
%19 = load i32, i32* %3
%20 = load i32, i32* @TIOCSSERIAL
%21 = call i32 @ioctl(i32 %19, i32 %20, %struct.serial_struct* %4)
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = load i32, i32* %5
store i32 %25, i32* %2
br label %29
26: ; preds = %13
br label %27
27: ; preds = %26
%28 = load i32, i32* %5
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %24, %11
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
%struct.serial_struct = type { i32, i32 }
@TIOCGSERIAL = global i32 0
@ASYNC_LOW_LATENCY = global i32 0
@TIOCSSERIAL = global i32 0
define i32 @carmen_serial_set_low_latency(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 eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i32, i32* @ASYNC_LOW_LATENCY
%9 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %2, i64 0, i32 1
%10 = load i32, i32* %9
%11 = or i32 %10, %8
store i32 %11, i32* %9
%12 = getelementptr inbounds %struct.serial_struct, %struct.serial_struct* %2, i64 0, i32 0
store i32 1, i32* %12
%13 = load i32, i32* @TIOCSSERIAL
%14 = call i32 @ioctl(i32 %0, i32 %13, %struct.serial_struct* %2)
br label %15
15: ; preds = %1, %7
ret i32 %5
}