#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 controller_info {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ TIOCMGET;
int TIOCM_DTR;
int TIOCM_RTS;
int /*<<< orphan*/ controller_output(struct controller_info *, char *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int strlen(char *);
void show_devcontrol(struct controller_info *cntlr, int fd) {
  char *str;
  int status;
  ioctl(fd, TIOCMGET, &status);
  if (status & TIOCM_RTS) {
    str = "RTSHI";
  } else {
    str = "RTSLO";
  }
  controller_output(cntlr, str, strlen(str));
  controller_output(cntlr, " ", 1);
  if (status & TIOCM_DTR) {
    str = "DTRHI";
  } else {
    str = "DTRLO";
  }
  controller_output(cntlr, str, strlen(str));
  controller_output(cntlr, " ", 1);
}


x86 assembly (clang, -O0):
<show_devcontrol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e8a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1179 <show_devcontrol+0x49>
lea    0xe90(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1184 <show_devcontrol+0x54>
lea    0xe86(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <controller_output@plt>
mov    -0x8(%rbp),%rdi
lea    0xe55(%rip),%rsi
mov    $0x1,%edx
call   1050 <controller_output@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e15(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e6 <show_devcontrol+0xb6>
lea    0xe31(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11f1 <show_devcontrol+0xc1>
lea    0xe27(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <controller_output@plt>
mov    -0x8(%rbp),%rdi
lea    0xde8(%rip),%rsi
mov    $0x1,%edx
call   1050 <controller_output@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_devcontrol>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %rdi,%r14
mov    0x2e93(%rip),%rcx
mov    (%rcx),%esi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
and    0xc(%rsp),%eax
lea    0xe9f(%rip),%rax
lea    0xe92(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <controller_output@plt>
lea    0xe7e(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <controller_output@plt>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
and    0xc(%rsp),%eax
lea    0xe62(%rip),%rax
lea    0xe55(%rip),%rbx
cmove  %rax,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <controller_output@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1050 <controller_output@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.controller_info = type { i32 }
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@.str = [6 x i8] c"RTSHI\00"
@.str.1 = [6 x i8] c"RTSLO\00"
@.str.2 = [2 x i8] c" \00"
@TIOCM_DTR = global i32 0
@.str.3 = [6 x i8] c"DTRHI\00"
@.str.4 = [6 x i8] c"DTRLO\00"
define void @show_devcontrol(%struct.controller_info* %0, i32 %1) {
%3 = alloca %struct.controller_info*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store %struct.controller_info* %0, %struct.controller_info** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @TIOCMGET
%9 = call i32 @ioctl(i32 %7, i32 %8, i32* %6)
%10 = load i32, i32* %6
%11 = load i32, i32* @TIOCM_RTS
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
br label %16
15: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %16
16: ; preds = %15, %14
%17 = load %struct.controller_info*, %struct.controller_info** %3
%18 = load i8*, i8** %5
%19 = load i8*, i8** %5
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @controller_output(%struct.controller_info* %17, i8* %18, i32 %20)
%22 = load %struct.controller_info*, %struct.controller_info** %3
%23 = call i32 @controller_output(%struct.controller_info* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%24 = load i32, i32* %6
%25 = load i32, i32* @TIOCM_DTR
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %16
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %5
br label %30
29: ; preds = %16
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8** %5
br label %30
30: ; preds = %29, %28
%31 = load %struct.controller_info*, %struct.controller_info** %3
%32 = load i8*, i8** %5
%33 = load i8*, i8** %5
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @controller_output(%struct.controller_info* %31, i8* %32, i32 %34)
%36 = load %struct.controller_info*, %struct.controller_info** %3
%37 = call i32 @controller_output(%struct.controller_info* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
%struct.controller_info = type { i32 }
@TIOCMGET = global i32 0
@TIOCM_RTS = global i32 0
@.str = [6 x i8] c"RTSHI\00"
@.str.1 = [6 x i8] c"RTSLO\00"
@.str.2 = [2 x i8] c" \00"
@TIOCM_DTR = global i32 0
@.str.3 = [6 x i8] c"DTRHI\00"
@.str.4 = [6 x i8] c"DTRLO\00"
define void @show_devcontrol(%struct.controller_info* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @TIOCMGET
%6 = call i32 @ioctl(i32 %1, i32 %5, i32* %3)
%7 = load i32, i32* %3
%8 = load i32, i32* @TIOCM_RTS
%9 = and i32 %8, %7
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0)
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @controller_output(%struct.controller_info* %0, i8* %11, i32 %12)
%14 = call i32 @controller_output(%struct.controller_info* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%15 = load i32, i32* %3
%16 = load i32, i32* @TIOCM_DTR
%17 = and i32 %16, %15
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @controller_output(%struct.controller_info* %0, i8* %19, i32 %20)
%22 = call i32 @controller_output(%struct.controller_info* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}