#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;
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ usleep(int);
void restart_mojo(int fd) {
  int status;
  ioctl(fd, TIOCMGET, &status);
  status &= ~TIOCM_DTR;
  ioctl(fd, TIOCMSET, &status);
  usleep(5 * 1000);
  for (int i = 0; i < 5; i++) {
    status &= ~TIOCM_DTR;
    ioctl(fd, TIOCMSET, &status);
    usleep(5 * 1000);
    status |= TIOCM_DTR;
    ioctl(fd, TIOCMSET, &status);
    usleep(5 * 1000);
  }
}


x86 assembly (clang, -O0):
<restart_mojo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jge    11ef <restart_mojo+0xcf>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1178 <restart_mojo+0x58>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<restart_mojo>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea7(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%r14
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    0x2e99(%rip),%r15
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    0x2e91(%rip),%r12
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
or     %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
or     %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
or     %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
or     %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
not    %eax
and    %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
mov    (%r15),%eax
or     %eax,0x4(%rsp)
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    $0x1388,%edi
call   1040 <usleep@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
define void @restart_mojo(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @TIOCMGET
%7 = call i32 @ioctl(i32 %5, i32 %6, i32* %3)
%8 = load i32, i32* @TIOCM_DTR
%9 = xor i32 %8, -1
%10 = load i32, i32* %3
%11 = and i32 %10, %9
store i32 %11, i32* %3
%12 = load i32, i32* %2
%13 = load i32, i32* @TIOCMSET
%14 = call i32 @ioctl(i32 %12, i32 %13, i32* %3)
%15 = call i32 @usleep(i32 5000)
store i32 0, i32* %4
br label %16
16: ; preds = %35, %1
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 5
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = load i32, i32* @TIOCM_DTR
%21 = xor i32 %20, -1
%22 = load i32, i32* %3
%23 = and i32 %22, %21
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = load i32, i32* @TIOCMSET
%26 = call i32 @ioctl(i32 %24, i32 %25, i32* %3)
%27 = call i32 @usleep(i32 5000)
%28 = load i32, i32* @TIOCM_DTR
%29 = load i32, i32* %3
%30 = or i32 %29, %28
store i32 %30, i32* %3
%31 = load i32, i32* %2
%32 = load i32, i32* @TIOCMSET
%33 = call i32 @ioctl(i32 %31, i32 %32, i32* %3)
%34 = call i32 @usleep(i32 5000)
br label %35
35: ; preds = %19
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %16
38: ; preds = %16
ret void
}

LLVM IR (-O2):
@TIOCMGET = global i32 0
@TIOCM_DTR = global i32 0
@TIOCMSET = global i32 0
define void @restart_mojo(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @TIOCMGET
%5 = call i32 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = load i32, i32* @TIOCM_DTR
%7 = xor i32 %6, -1
%8 = load i32, i32* %2
%9 = and i32 %8, %7
store i32 %9, i32* %2
%10 = load i32, i32* @TIOCMSET
%11 = call i32 @ioctl(i32 %0, i32 %10, i32* %2)
%12 = call i32 @usleep(i32 5000)
%13 = load i32, i32* @TIOCM_DTR
%14 = xor i32 %13, -1
%15 = load i32, i32* %2
%16 = and i32 %15, %14
store i32 %16, i32* %2
%17 = load i32, i32* @TIOCMSET
%18 = call i32 @ioctl(i32 %0, i32 %17, i32* %2)
%19 = call i32 @usleep(i32 5000)
%20 = load i32, i32* @TIOCM_DTR
%21 = load i32, i32* %2
%22 = or i32 %21, %20
store i32 %22, i32* %2
%23 = load i32, i32* @TIOCMSET
%24 = call i32 @ioctl(i32 %0, i32 %23, i32* %2)
%25 = call i32 @usleep(i32 5000)
%26 = load i32, i32* @TIOCM_DTR
%27 = xor i32 %26, -1
%28 = load i32, i32* %2
%29 = and i32 %28, %27
store i32 %29, i32* %2
%30 = load i32, i32* @TIOCMSET
%31 = call i32 @ioctl(i32 %0, i32 %30, i32* %2)
%32 = call i32 @usleep(i32 5000)
%33 = load i32, i32* @TIOCM_DTR
%34 = load i32, i32* %2
%35 = or i32 %34, %33
store i32 %35, i32* %2
%36 = load i32, i32* @TIOCMSET
%37 = call i32 @ioctl(i32 %0, i32 %36, i32* %2)
%38 = call i32 @usleep(i32 5000)
%39 = load i32, i32* @TIOCM_DTR
%40 = xor i32 %39, -1
%41 = load i32, i32* %2
%42 = and i32 %41, %40
store i32 %42, i32* %2
%43 = load i32, i32* @TIOCMSET
%44 = call i32 @ioctl(i32 %0, i32 %43, i32* %2)
%45 = call i32 @usleep(i32 5000)
%46 = load i32, i32* @TIOCM_DTR
%47 = load i32, i32* %2
%48 = or i32 %47, %46
store i32 %48, i32* %2
%49 = load i32, i32* @TIOCMSET
%50 = call i32 @ioctl(i32 %0, i32 %49, i32* %2)
%51 = call i32 @usleep(i32 5000)
%52 = load i32, i32* @TIOCM_DTR
%53 = xor i32 %52, -1
%54 = load i32, i32* %2
%55 = and i32 %54, %53
store i32 %55, i32* %2
%56 = load i32, i32* @TIOCMSET
%57 = call i32 @ioctl(i32 %0, i32 %56, i32* %2)
%58 = call i32 @usleep(i32 5000)
%59 = load i32, i32* @TIOCM_DTR
%60 = load i32, i32* %2
%61 = or i32 %60, %59
store i32 %61, i32* %2
%62 = load i32, i32* @TIOCMSET
%63 = call i32 @ioctl(i32 %0, i32 %62, i32* %2)
%64 = call i32 @usleep(i32 5000)
%65 = load i32, i32* @TIOCM_DTR
%66 = xor i32 %65, -1
%67 = load i32, i32* %2
%68 = and i32 %67, %66
store i32 %68, i32* %2
%69 = load i32, i32* @TIOCMSET
%70 = call i32 @ioctl(i32 %0, i32 %69, i32* %2)
%71 = call i32 @usleep(i32 5000)
%72 = load i32, i32* @TIOCM_DTR
%73 = load i32, i32* %2
%74 = or i32 %73, %72
store i32 %74, i32* %2
%75 = load i32, i32* @TIOCMSET
%76 = call i32 @ioctl(i32 %0, i32 %75, i32* %2)
%77 = call i32 @usleep(i32 5000)
ret void
}