#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*/ OpenCOM(int, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int OpenCOMEx(char *port_zstr) {
  int portnum;
  if (strcmp(port_zstr, "serial0") == 0)
    portnum = 0;
  else if (strcmp(port_zstr, "serial1") == 0)
    portnum = 1;
  else if (strcmp(port_zstr, "serial2") == 0)
    portnum = 2;
  else
    return -1;
  if (!OpenCOM(portnum, NULL)) {
    return -1;
  }
  return portnum;
}


x86 assembly (clang, -O0):
<OpenCOMEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1152 <OpenCOMEx+0x32>
movl   $0x0,-0x14(%rbp)
jmp    11b4 <OpenCOMEx+0x94>
mov    -0x10(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1178 <OpenCOMEx+0x58>
movl   $0x1,-0x14(%rbp)
jmp    11af <OpenCOMEx+0x8f>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    119e <OpenCOMEx+0x7e>
movl   $0x2,-0x14(%rbp)
jmp    11aa <OpenCOMEx+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <OpenCOMEx+0xbb>
jmp    11af <OpenCOMEx+0x8f>
jmp    11b4 <OpenCOMEx+0x94>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <OpenCOM@plt>
cmp    $0x0,%eax
jne    11d5 <OpenCOMEx+0xb5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <OpenCOMEx+0xbb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenCOMEx>:
push   %rbx
mov    %rdi,%rbx
lea    0xed5(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1167 <OpenCOMEx+0x47>
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     116b <OpenCOMEx+0x4b>
lea    0xec0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
je     1172 <OpenCOMEx+0x52>
pop    %rbx
ret
xor    %ebx,%ebx
jmp    1177 <OpenCOMEx+0x57>
mov    $0x1,%ebx
jmp    1177 <OpenCOMEx+0x57>
mov    $0x2,%ebx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <OpenCOM@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
or     %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"serial0\00"
@.str.1 = [8 x i8] c"serial1\00"
@.str.2 = [8 x i8] c"serial2\00"
define i32 @OpenCOMEx(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %4
br label %22
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 1, i32* %4
br label %21
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 2, i32* %4
br label %20
19: ; preds = %14
store i32 -1, i32* %2
br label %29
20: ; preds = %18
br label %21
21: ; preds = %20, %13
br label %22
22: ; preds = %21, %8
%23 = load i32, i32* %4
%24 = call i32 @OpenCOM(i32 %23, i32* null)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
store i32 -1, i32* %2
br label %29
27: ; preds = %22
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %26, %19
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
@.str = [8 x i8] c"serial0\00"
@.str.1 = [8 x i8] c"serial1\00"
@.str.2 = [8 x i8] c"serial2\00"
define i32 @OpenCOMEx(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7, %4, %1
%11 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ]
%12 = tail call i32 @OpenCOM(i32 %11, i32* null)
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 -1, i32 %11
br label %15
15: ; preds = %10, %7
%16 = phi i32 [ -1, %7 ], [ %14, %10 ]
ret i32 %16
}