#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 /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
void set_modem_lines(int fd, int bits, int mask) {
  int status, ret;
  ret = ioctl(fd, TIOCMGET, &status);
  if (ret < 0) {
    perror("TIOCMGET failed");
    exit(1);
  }
  status = (status & ~mask) | (bits & mask);
  ret = ioctl(fd, TIOCMSET, &status);
  if (ret < 0) {
    perror("TIOCMSET failed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<set_modem_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1179 <set_modem_lines+0x49>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    -0x8(%rbp),%ecx
and    -0xc(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11c7 <set_modem_lines+0x97>
lea    0xe58(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_modem_lines>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
call   1030 <ioctl@plt>
test   %eax,%eax
js     1187 <set_modem_lines+0x57>
mov    0xc(%rsp),%eax
xor    %eax,%ebp
and    %r14d,%ebp
xor    %eax,%ebp
mov    %ebp,0xc(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
js     1190 <set_modem_lines+0x60>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe72(%rip),%rdi
jmp    1197 <set_modem_lines+0x67>
lea    0xe79(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@TIOCMGET = global i32 0
@.str = [16 x i8] c"TIOCMGET failed\00"
@TIOCMSET = global i32 0
@.str.1 = [16 x i8] c"TIOCMSET failed\00"
define void @set_modem_lines(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = load i32, i32* @TIOCMGET
%7 = call i32 @ioctl(i32 %0, i32 %6, i32* %4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = load i32, i32* %4
%14 = xor i32 %2, -1
%15 = and i32 %13, %14
%16 = and i32 %2, %1
%17 = or i32 %15, %16
store i32 %17, i32* %4
%18 = load i32, i32* @TIOCMSET
%19 = call i32 @ioctl(i32 %0, i32 %18, i32* %4)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %12
ret void
}