#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_set_dtr(int fd, unsigned char on) {
  int flags;
  if (ioctl(fd, TIOCMGET, &flags) < 0) {
    perror("ERROR: could not reset, getting V24 line status failed");
    return;
  }
  if (on) {
    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_set_dtr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1161 <com_set_dtr+0x41>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
jmp    11bc <com_set_dtr+0x9c>
cmpb   $0x0,-0x5(%rbp)
je     117f <com_set_dtr+0x5f>
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <com_set_dtr+0x71>
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11bc <com_set_dtr+0x9c>
lea    0xe80(%rip),%rdi
call   1040 <perror@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<com_set_dtr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
js     117e <com_set_dtr+0x5e>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
test   %bpl,%bpl
je     1153 <com_set_dtr+0x33>
or     0x4(%rsp),%eax
jmp    1159 <com_set_dtr+0x39>
not    %eax
and    0x4(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1187 <com_set_dtr+0x67>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7b(%rip),%rdi
jmp    118e <com_set_dtr+0x6e>
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
jmp    1177 <com_set_dtr+0x57>

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_set_dtr(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
%6 = load i32, i32* %3
%7 = load i32, i32* @TIOCMGET
%8 = call i64 @ioctl(i32 %6, i32 %7, i32* %5)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %31
12: ; preds = %2
%13 = load i8, i8* %4
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @TIOCM_DTR
%17 = load i32, i32* %5
%18 = or i32 %17, %16
store i32 %18, i32* %5
br label %24
19: ; preds = %12
%20 = load i32, i32* @TIOCM_DTR
%21 = xor i32 %20, -1
%22 = load i32, i32* %5
%23 = and i32 %22, %21
store i32 %23, i32* %5
br label %24
24: ; preds = %19, %15
%25 = load i32, i32* %3
%26 = load i32, i32* @TIOCMSET
%27 = call i64 @ioctl(i32 %25, i32 %26, i32* %5)
%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 = %10, %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_set_dtr(i32 %0, i8 zeroext %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @TIOCMGET
%6 = call i64 @ioctl(i32 %0, i32 %5, i32* %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %2
%9 = icmp eq i8 %1, 0
%10 = load i32, i32* @TIOCM_DTR
br i1 %9, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* %3
%13 = or i32 %12, %10
br label %18
14: ; preds = %8
%15 = xor i32 %10, -1
%16 = load i32, i32* %3
%17 = and i32 %16, %15
br label %18
18: ; preds = %14, %11
%19 = phi i32 [ %17, %14 ], [ %13, %11 ]
store i32 %19, i32* %3
%20 = load i32, i32* @TIOCMSET
%21 = call i64 @ioctl(i32 %0, i32 %20, i32* %3)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18, %2
%24 = phi i8* [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), %18 ]
%25 = call i32 @perror(i8* %24)
br label %26
26: ; preds = %23, %18
ret void
}