#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 */
scalar_t__ findprop(char const *);
int /*<<< orphan*/ serial_done();
scalar_t__ serial_init(char const *, int);
int popenport(const char *port, int baud, int noreset) {
  if (serial_init(port, baud) == 0)
    return -1;
  if (noreset)
    return 0;
  if (findprop(port) != 0) {
    serial_done();
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<popenport>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <serial_init@plt>
cmp    $0x0,%rax
jne    1164 <popenport+0x34>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <popenport+0x77>
cmpl   $0x0,-0x18(%rbp)
je     117a <popenport+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <popenport+0x77>
mov    -0x10(%rbp),%rdi
call   1030 <findprop@plt>
cmp    $0x0,%rax
je     11a0 <popenport+0x70>
mov    $0x0,%al
call   1040 <serial_done@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11a7 <popenport+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<popenport>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbx
call   1050 <serial_init@plt>
test   %rax,%rax
je     1166 <popenport+0x36>
xor    %ebp,%ebp
test   %r14d,%r14d
jne    116b <popenport+0x3b>
mov    %rbx,%rdi
call   1030 <findprop@plt>
test   %rax,%rax
je     116b <popenport+0x3b>
xor    %eax,%eax
call   1040 <serial_done@plt>
mov    $0xfffffffe,%ebp
jmp    116b <popenport+0x3b>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @popenport(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i8*, i8** %5
%9 = load i32, i32* %6
%10 = call i64 @serial_init(i8* %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %24
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %4
br label %24
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i64 @findprop(i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 (...) @serial_done()
store i32 -2, i32* %4
br label %24
23: ; preds = %17
store i32 0, i32* %4
br label %24
24: ; preds = %23, %21, %16, %12
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
define i32 @popenport(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @serial_init(i8* %0, i32 %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = tail call i64 @findprop(i8* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 (...) @serial_done()
br label %13
13: ; preds = %8, %6, %3, %11
%14 = phi i32 [ -2, %11 ], [ -1, %3 ], [ 0, %6 ], [ 0, %8 ]
ret i32 %14
}