#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_DTR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
void main(void) {
  int fd;
  fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY);
  if (fd == -1) {
    printf("ttyUSB0 opening error, exiting\n");
    exit(1);
  } else {
    printf("ttyUSB0 opened successfully\n");
    int DTR_flag;
    DTR_flag = TIOCM_DTR;
    while (1) {
      printf("DTR = 1\n");
      ioctl(fd, TIOCMBIS, &DTR_flag);
      sleep(1);
      printf("DTR = 0\n");
      ioctl(fd, TIOCMBIC, &DTR_flag);
      sleep(1);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e60(%rip),%rax
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1199 <main+0x49>
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11b1 <main+0x61>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e86(%rip),%rax
mov    0x2e5f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1201 <main+0xb1>
mov    %eax,%ebx
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
lea    0xe85(%rip),%r14
mov    0x2e25(%rip),%r13
lea    0x4(%rsp),%r15
lea    0xe7a(%rip),%r12
mov    0x2e02(%rip),%rbp
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <puts@plt>
mov    0x0(%r13),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%esi
mov    %ebx,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11c0 <main+0x70>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@.str.1 = [32 x i8] c"ttyUSB0 opening error, exiting\0A\00"
@.str.2 = [29 x i8] c"ttyUSB0 opened successfully\0A\00"
@TIOCM_DTR = global i32 0
@.str.3 = [9 x i8] c"DTR = 1\0A\00"
@TIOCMBIS = global i32 0
@.str.4 = [9 x i8] c"DTR = 0\0A\00"
@TIOCMBIC = global i32 0
define void @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 ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @TIOCM_DTR
store i32 %14, i32* %2
br label %15
15: ; preds = %12, %15
%16 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = load i32, i32* %1
%18 = load i32, i32* @TIOCMBIS
%19 = call i32 @ioctl(i32 %17, i32 %18, i32* %2)
%20 = call i32 @sleep(i32 1)
%21 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* %1
%23 = load i32, i32* @TIOCMBIC
%24 = call i32 @ioctl(i32 %22, i32 %23, i32* %2)
%25 = call i32 @sleep(i32 1)
br label %15
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/ttyUSB0\00"
@O_RDWR = global i32 0
@O_NOCTTY = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMBIS = global i32 0
@TIOCMBIC = global i32 0
@str = [28 x i8] c"ttyUSB0 opened successfully\00"
@str.5 = [8 x i8] c"DTR = 1\00"
@str.6 = [8 x i8] c"DTR = 0\00"
@str.7 = [31 x i8] c"ttyUSB0 opening error, exiting\00"
define void @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 ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.7, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%12 = bitcast i32* %1 to i8*
%13 = load i32, i32* @TIOCM_DTR
store i32 %13, i32* %1
br label %14
14: ; preds = %14, %10
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.5, i64 0, i64 0))
%16 = load i32, i32* @TIOCMBIS
%17 = call i32 @ioctl(i32 %5, i32 %16, i32* %1)
%18 = call i32 @sleep(i32 1)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.6, i64 0, i64 0))
%20 = load i32, i32* @TIOCMBIC
%21 = call i32 @ioctl(i32 %5, i32 %20, i32* %1)
%22 = call i32 @sleep(i32 1)
br label %14
}