#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 O_NOCTTY;
int O_RDWR;
int /*<<< orphan*/ TIOCMBIC;
int /*<<< orphan*/ TIOCMBIS;
int TIOCM_RTS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
main() {
  int fd;
  fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY);
  int RTS_flag;
  RTS_flag = TIOCM_RTS;
  ioctl(fd, TIOCMBIS, &RTS_flag);
  getchar();
  ioctl(fd, TIOCMBIC, &RTS_flag);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    0x2e70(%rip),%rax
or     (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x4(%rbp),%edi
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e9d(%rip),%rax
mov    0x2e76(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xea3(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_NOCTTY
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* @TIOCM_RTS
store i32 %7, i32* %2
%8 = load i32, i32* %1
%9 = load i32, i32* @TIOCMBIS
%10 = call i32 @ioctl(i32 %8, i32 %9, i32* %2)
%11 = call i32 (...) @getchar()
%12 = load i32, i32* %1
%13 = load i32, i32* @TIOCMBIC
%14 = call i32 @ioctl(i32 %12, i32 %13, i32* %2)
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ttyS0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@TIOCM_RTS = global i32 0
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @O_RDWR
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = bitcast i32* %1 to i8*
%7 = load i32, i32* @TIOCM_RTS
store i32 %7, i32* %1
%8 = load i32, i32* @TIOCMBIS
%9 = call i32 @ioctl(i32 %5, i32 %8, i32* %1)
%10 = call i32 (...) @getchar()
%11 = load i32, i32* @TIOCMBIC
%12 = call i32 @ioctl(i32 %5, i32 %11, i32* %1)
%13 = call i32 @close(i32 %5)
ret i32 0
}