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

/* Variables and functions */
int TIOCM_DSR;
int TIOCM_DTR;
int TIOCM_RTS;
int get_serial_lines(int);
scalar_t__ init_port(int);
int /*<<< orphan*/ set_serial_lines(int, int);
int setup_serial_port(int, int, struct termios *);
int tcgetattr(int, struct termios *);
int /*<<< orphan*/ usleep(int);
int init_pnp_com_seq1(int fd) {
  int modem_lines;
  int temp;
  int dsr_status;
  int rc = 3;
  struct termios portattr;
  ;
  ;
  if (init_port(fd))
    return 1;
  modem_lines = get_serial_lines(fd);
  modem_lines |= TIOCM_DTR;
  modem_lines &= ~TIOCM_RTS;
  set_serial_lines(fd, modem_lines);
  usleep(200000);
  dsr_status = get_serial_lines(fd) & TIOCM_DSR;
  if (!dsr_status) {
    ;
    ;
  }
  temp = tcgetattr(fd, &portattr);
  if (temp < 0)
    return 1;
  temp = setup_serial_port(fd, 7, &portattr);
  if (temp < 0)
    return 1;
  modem_lines &= ~(TIOCM_RTS | TIOCM_DTR);
  set_serial_lines(fd, modem_lines);
  usleep(200000);
  modem_lines |= TIOCM_DTR;
  set_serial_lines(fd, modem_lines);
  usleep(200000);
  modem_lines |= TIOCM_RTS;
  set_serial_lines(fd, modem_lines);
  usleep(200000);
  return rc;
}


x86 assembly (clang, -O0):
<init_pnp_com_seq1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <init_port@plt>
cmp    $0x0,%rax
je     1190 <init_pnp_com_seq1+0x30>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <init_pnp_com_seq1+0x161>
mov    -0x8(%rbp),%edi
call   1050 <get_serial_lines@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    -0x8(%rbp),%edi
call   1050 <get_serial_lines@plt>
mov    0x2e08(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11f4 <init_pnp_com_seq1+0x94>
jmp    11f4 <init_pnp_com_seq1+0x94>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1070 <tcgetattr@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1219 <init_pnp_com_seq1+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <init_pnp_com_seq1+0x161>
mov    -0x8(%rbp),%edi
mov    $0x7,%esi
lea    -0x20(%rbp),%rdx
call   1040 <setup_serial_port@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1243 <init_pnp_com_seq1+0xe3>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <init_pnp_com_seq1+0x161>
mov    0x2d96(%rip),%rax
mov    (%rax),%eax
mov    0x2d85(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_pnp_com_seq1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   1060 <init_port@plt>
mov    $0x1,%r14d
test   %rax,%rax
jne    1232 <init_pnp_com_seq1+0xd2>
mov    %ebx,%edi
call   1050 <get_serial_lines@plt>
mov    0x2e50(%rip),%r12
or     (%r12),%eax
mov    0x2e4d(%rip),%r15
mov    (%r15),%ebp
not    %ebp
and    %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    %ebx,%edi
call   1050 <get_serial_lines@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1070 <tcgetattr@plt>
test   %eax,%eax
js     1232 <init_pnp_com_seq1+0xd2>
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
mov    $0x7,%esi
call   1040 <setup_serial_port@plt>
test   %eax,%eax
js     1232 <init_pnp_com_seq1+0xd2>
mov    (%r12),%eax
or     (%r15),%eax
not    %eax
and    %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
or     (%r12),%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
or     (%r15),%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <set_serial_lines@plt>
mov    $0x30d40,%edi
call   1080 <usleep@plt>
mov    $0x3,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCM_DSR = global i32 0
define i32 @init_pnp_com_seq1(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.termios
store i32 %0, i32* %3
store i32 3, i32* %7
%9 = load i32, i32* %3
%10 = call i64 @init_port(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 1, i32* %2
br label %72
13: ; preds = %1
%14 = load i32, i32* %3
%15 = call i32 @get_serial_lines(i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* @TIOCM_DTR
%17 = load i32, i32* %4
%18 = or i32 %17, %16
store i32 %18, i32* %4
%19 = load i32, i32* @TIOCM_RTS
%20 = xor i32 %19, -1
%21 = load i32, i32* %4
%22 = and i32 %21, %20
store i32 %22, i32* %4
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @set_serial_lines(i32 %23, i32 %24)
%26 = call i32 @usleep(i32 200000)
%27 = load i32, i32* %3
%28 = call i32 @get_serial_lines(i32 %27)
%29 = load i32, i32* @TIOCM_DSR
%30 = and i32 %28, %29
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %34, label %33
33: ; preds = %13
br label %34
34: ; preds = %33, %13
%35 = load i32, i32* %3
%36 = call i32 @tcgetattr(i32 %35, %struct.termios* %8)
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 1, i32* %2
br label %72
40: ; preds = %34
%41 = load i32, i32* %3
%42 = call i32 @setup_serial_port(i32 %41, i32 7, %struct.termios* %8)
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %2
br label %72
46: ; preds = %40
%47 = load i32, i32* @TIOCM_RTS
%48 = load i32, i32* @TIOCM_DTR
%49 = or i32 %47, %48
%50 = xor i32 %49, -1
%51 = load i32, i32* %4
%52 = and i32 %51, %50
store i32 %52, i32* %4
%53 = load i32, i32* %3
%54 = load i32, i32* %4
%55 = call i32 @set_serial_lines(i32 %53, i32 %54)
%56 = call i32 @usleep(i32 200000)
%57 = load i32, i32* @TIOCM_DTR
%58 = load i32, i32* %4
%59 = or i32 %58, %57
store i32 %59, i32* %4
%60 = load i32, i32* %3
%61 = load i32, i32* %4
%62 = call i32 @set_serial_lines(i32 %60, i32 %61)
%63 = call i32 @usleep(i32 200000)
%64 = load i32, i32* @TIOCM_RTS
%65 = load i32, i32* %4
%66 = or i32 %65, %64
store i32 %66, i32* %4
%67 = load i32, i32* %3
%68 = load i32, i32* %4
%69 = call i32 @set_serial_lines(i32 %67, i32 %68)
%70 = call i32 @usleep(i32 200000)
%71 = load i32, i32* %7
store i32 %71, i32* %2
br label %72
72: ; preds = %46, %45, %39, %12
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TIOCM_DTR = global i32 0
@TIOCM_RTS = global i32 0
@TIOCM_DSR = global i32 0
define i32 @init_pnp_com_seq1(i32 %0) {
%2 = alloca %struct.termios
%3 = bitcast %struct.termios* %2 to i8*
%4 = tail call i64 @init_port(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %37
6: ; preds = %1
%7 = tail call i32 @get_serial_lines(i32 %0)
%8 = load i32, i32* @TIOCM_DTR
%9 = or i32 %8, %7
%10 = load i32, i32* @TIOCM_RTS
%11 = xor i32 %10, -1
%12 = and i32 %9, %11
%13 = tail call i32 @set_serial_lines(i32 %0, i32 %12)
%14 = tail call i32 @usleep(i32 200000)
%15 = tail call i32 @get_serial_lines(i32 %0)
%16 = call i32 @tcgetattr(i32 %0, %struct.termios* %2)
%17 = icmp slt i32 %16, 0
br i1 %17, label %37, label %18
18: ; preds = %6
%19 = call i32 @setup_serial_port(i32 %0, i32 7, %struct.termios* %2)
%20 = icmp slt i32 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %18
%22 = load i32, i32* @TIOCM_RTS
%23 = load i32, i32* @TIOCM_DTR
%24 = or i32 %23, %22
%25 = xor i32 %24, -1
%26 = and i32 %12, %25
%27 = call i32 @set_serial_lines(i32 %0, i32 %26)
%28 = call i32 @usleep(i32 200000)
%29 = load i32, i32* @TIOCM_DTR
%30 = or i32 %29, %26
%31 = call i32 @set_serial_lines(i32 %0, i32 %30)
%32 = call i32 @usleep(i32 200000)
%33 = load i32, i32* @TIOCM_RTS
%34 = or i32 %33, %30
%35 = call i32 @set_serial_lines(i32 %0, i32 %34)
%36 = call i32 @usleep(i32 200000)
br label %37
37: ; preds = %18, %6, %1, %21
%38 = phi i32 [ 3, %21 ], [ 1, %1 ], [ 1, %6 ], [ 1, %18 ]
ret i32 %38
}