#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 /*<<< orphan*/ TIOCMGET;
int /*<<< orphan*/ TIOCMSET;
int TIOCM_DTR;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
void com_toggle_dtr(int fd) {
  int flags;
  if (ioctl(fd, TIOCMGET, &flags) < 0) {
    perror("ERROR: could not reset, getting V24 line status failed");
    return;
  }
  if (flags & TIOCM_DTR) {
    flags &= ~TIOCM_DTR;
  } else {
    flags |= TIOCM_DTR;
  }
  if (ioctl(fd, TIOCMSET, &flags) < 0) {
    perror("ERROR: could not reset, setting V24 line status failed");
  }
}


x86 assembly (clang, -O0):
<com_toggle_dtr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    115b <com_toggle_dtr+0x3b>
lea    0xeaf(%rip),%rdi
call   1040 <perror@plt>
jmp    11c1 <com_toggle_dtr+0xa1>
mov    -0x8(%rbp),%eax
mov    0x2e7b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1187 <com_toggle_dtr+0x67>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1196 <com_toggle_dtr+0x76>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11c1 <com_toggle_dtr+0xa1>
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<com_toggle_dtr>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     117f <com_toggle_dtr+0x5f>
mov    0xc(%rsp),%eax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
or     %eax,%edx
mov    %ecx,%esi
not    %esi
and    %eax,%esi
test   %eax,%ecx
cmove  %edx,%esi
mov    %esi,0xc(%rsp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1188 <com_toggle_dtr+0x68>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7a(%rip),%rdi
jmp    118f <com_toggle_dtr+0x6f>
lea    0xea8(%rip),%rdi
call   1040 <perror@plt>
jmp    1179 <com_toggle_dtr+0x59>

LLVM IR (-O0):
@TIOCMGET = global i32 0
@.str = [55 x i8] c"ERROR: could not reset, getting V24 line status failed\00"
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [55 x i8] c"ERROR: could not reset, setting V24 line status failed\00"
define void @com_toggle_dtr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @TIOCMGET
%6 = call i64 @ioctl(i32 %4, i32 %5, i32* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %31
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @TIOCM_DTR
%13 = and i32 %11, %12
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @TIOCM_DTR
%17 = xor i32 %16, -1
%18 = load i32, i32* %3
%19 = and i32 %18, %17
store i32 %19, i32* %3
br label %24
20: ; preds = %10
%21 = load i32, i32* @TIOCM_DTR
%22 = load i32, i32* %3
%23 = or i32 %22, %21
store i32 %23, i32* %3
br label %24
24: ; preds = %20, %15
%25 = load i32, i32* %2
%26 = load i32, i32* @TIOCMSET
%27 = call i64 @ioctl(i32 %25, i32 %26, i32* %3)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %8, %29, %24
ret void
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@.str = [55 x i8] c"ERROR: could not reset, getting V24 line status failed\00"
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
@.str.1 = [55 x i8] c"ERROR: could not reset, setting V24 line status failed\00"
define void @com_toggle_dtr(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @TIOCMGET
%5 = call i64 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = load i32, i32* %2
%9 = load i32, i32* @TIOCM_DTR
%10 = and i32 %9, %8
%11 = icmp eq i32 %10, 0
%12 = or i32 %9, %8
%13 = xor i32 %9, -1
%14 = and i32 %8, %13
%15 = select i1 %11, i32 %12, i32 %14
store i32 %15, i32* %2
%16 = load i32, i32* @TIOCMSET
%17 = call i64 @ioctl(i32 %0, i32 %16, i32* %2)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %7, %1
%20 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), %7 ]
%21 = call i32 @perror(i8* %20)
br label %22
22: ; preds = %19, %7
ret void
}