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

/* Variables and functions */
struct mio_hdl *_mio_aucat_open(char const *, unsigned int, int);
int /*<<< orphan*/ _sndio_issetugid();
scalar_t__ _sndio_parsetype(char const *, char *);
char *getenv(char *);
scalar_t__ strcmp(char const *, char *);
struct mio_hdl *mio_open(const char *str, unsigned int mode, int nbio) {
  static char portany[] = "default";
  struct mio_hdl *hdl;
  if ((mode & (4 | 8)) == 0)
    return NULL;
  if (str == NULL)
    str = portany;
  if (strcmp(str, portany) == 0 && !_sndio_issetugid()) {
    str = getenv("MIDIDEVICE");
    if (str == NULL)
      str = portany;
  }
  if (strcmp(str, portany) == 0) {
    hdl = _mio_aucat_open("midithru/0", mode, nbio);
    if (hdl != NULL)
      return hdl;
    return NULL;
  }
  if (_sndio_parsetype(str, "snd") || _sndio_parsetype(str, "midithru") ||
      _sndio_parsetype(str, "midi"))
    return _mio_aucat_open(str, mode, nbio);
  if (_sndio_parsetype(str, "rmidi"))
    return NULL;
  do {
  } while (0);
  return NULL;
}


x86 assembly (clang, -O0):
<mio_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0xc,%eax
cmp    $0x0,%eax
jne    117e <mio_open+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    12dd <mio_open+0x18d>
cmpq   $0x0,-0x10(%rbp)
jne    1194 <mio_open+0x44>
lea    0x2eb8(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0x2ea9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e9 <mio_open+0x99>
mov    $0x0,%al
call   1040 <_sndio_issetugid@plt>
cmp    $0x0,%eax
jne    11e9 <mio_open+0x99>
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e4 <mio_open+0x94>
lea    0x2e68(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e9 <mio_open+0x99>
mov    -0x10(%rbp),%rdi
lea    0x2e54(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123e <mio_open+0xee>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdfb(%rip),%rdi
call   1070 <_mio_aucat_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1231 <mio_open+0xe1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12dd <mio_open+0x18d>
movq   $0x0,-0x8(%rbp)
jmp    12dd <mio_open+0x18d>
mov    -0x10(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
jne    128c <mio_open+0x13c>
mov    -0x10(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
jne    128c <mio_open+0x13c>
mov    -0x10(%rbp),%rdi
lea    0xda7(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
je     12a4 <mio_open+0x154>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <_mio_aucat_open@plt>
mov    %rax,-0x8(%rbp)
jmp    12dd <mio_open+0x18d>
mov    -0x10(%rbp),%rdi
lea    0xd74(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
je     12cb <mio_open+0x17b>
movq   $0x0,-0x8(%rbp)
jmp    12dd <mio_open+0x18d>
jmp    12d0 <mio_open+0x180>
jmp    12d5 <mio_open+0x185>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mio_open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
test   $0xc,%r15b
je     1229 <mio_open+0xd9>
mov    %edx,%r14d
mov    %rdi,%rbx
test   %rdi,%rdi
lea    0x2ed4(%rip),%rbp
cmove  %rbp,%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a9 <mio_open+0x59>
xor    %eax,%eax
call   1040 <_sndio_issetugid@plt>
test   %eax,%eax
jne    11a9 <mio_open+0x59>
lea    0xe66(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
cmovne %rax,%rbp
mov    %rbp,%rbx
lea    0x2e98(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fe <mio_open+0xae>
lea    0xe52(%rip),%rsi
mov    %rbx,%rdi
call   1060 <_sndio_parsetype@plt>
test   %rax,%rax
jne    11f9 <mio_open+0xa9>
lea    0xe42(%rip),%rsi
mov    %rbx,%rdi
call   1060 <_sndio_parsetype@plt>
test   %rax,%rax
jne    11f9 <mio_open+0xa9>
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1060 <_sndio_parsetype@plt>
test   %rax,%rax
je     121a <mio_open+0xca>
mov    %rbx,%rdi
jmp    1205 <mio_open+0xb5>
lea    0xe06(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_mio_aucat_open@plt>
lea    0xe02(%rip),%rsi
mov    %rbx,%rdi
call   1060 <_sndio_parsetype@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mio_hdl = type { i32 }
@mio_open.portany = internal global [8 x i8] c"default\00"
@.str = [11 x i8] c"MIDIDEVICE\00"
@.str.1 = [11 x i8] c"midithru/0\00"
@.str.2 = [4 x i8] c"snd\00"
@.str.3 = [9 x i8] c"midithru\00"
@.str.4 = [5 x i8] c"midi\00"
@.str.5 = [6 x i8] c"rmidi\00"
define %struct.mio_hdl* @mio_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.mio_hdl*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.mio_hdl*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = and i32 %9, 12
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store %struct.mio_hdl* null, %struct.mio_hdl** %4
br label %68
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0), i8** %5
br label %17
17: ; preds = %16, %13
%18 = load i8*, i8** %5
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %17
%22 = call i32 (...) @_sndio_issetugid()
%23 = icmp ne i32 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0), i8** %5
br label %29
29: ; preds = %28, %24
br label %30
30: ; preds = %29, %21, %17
%31 = load i8*, i8** %5
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = call %struct.mio_hdl* @_mio_aucat_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
store %struct.mio_hdl* %37, %struct.mio_hdl** %8
%38 = load %struct.mio_hdl*, %struct.mio_hdl** %8
%39 = icmp ne %struct.mio_hdl* %38, null
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = load %struct.mio_hdl*, %struct.mio_hdl** %8
store %struct.mio_hdl* %41, %struct.mio_hdl** %4
br label %68
42: ; preds = %34
store %struct.mio_hdl* null, %struct.mio_hdl** %4
br label %68
43: ; preds = %30
%44 = load i8*, i8** %5
%45 = call i64 @_sndio_parsetype(i8* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i64 %45, 0
br i1 %46, label %55, label %47
47: ; preds = %43
%48 = load i8*, i8** %5
%49 = call i64 @_sndio_parsetype(i8* %48, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%50 = icmp ne i64 %49, 0
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = call i64 @_sndio_parsetype(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %51, %47, %43
%56 = load i8*, i8** %5
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = call %struct.mio_hdl* @_mio_aucat_open(i8* %56, i32 %57, i32 %58)
store %struct.mio_hdl* %59, %struct.mio_hdl** %4
br label %68
60: ; preds = %51
%61 = load i8*, i8** %5
%62 = call i64 @_sndio_parsetype(i8* %61, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %60
store %struct.mio_hdl* null, %struct.mio_hdl** %4
br label %68
65: ; preds = %60
br label %66
66: ; preds = %65
br label %67
67: ; preds = %66
store %struct.mio_hdl* null, %struct.mio_hdl** %4
br label %68
68: ; preds = %67, %64, %55, %42, %40, %12
%69 = load %struct.mio_hdl*, %struct.mio_hdl** %4
ret %struct.mio_hdl* %69
}

LLVM IR (-O2):
%struct.mio_hdl = type { i32 }
@mio_open.portany = internal global [8 x i8] c"default\00"
@.str = [11 x i8] c"MIDIDEVICE\00"
@.str.1 = [11 x i8] c"midithru/0\00"
@.str.2 = [4 x i8] c"snd\00"
@.str.3 = [9 x i8] c"midithru\00"
@.str.4 = [5 x i8] c"midi\00"
@.str.5 = [6 x i8] c"rmidi\00"
define %struct.mio_hdl* @mio_open(i8* %0, i32 %1, i32 %2) {
%4 = and i32 %1, 12
%5 = icmp eq i32 %4, 0
br i1 %5, label %37, label %6
6: ; preds = %3
%7 = icmp eq i8* %0, null
%8 = select i1 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0), i8* %0
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = tail call i32 (...) @_sndio_issetugid()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
%17 = select i1 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0), i8* %15
br label %18
18: ; preds = %14, %11, %6
%19 = phi i8* [ %8, %11 ], [ %17, %14 ], [ %8, %6 ]
%20 = tail call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @mio_open.portany, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call %struct.mio_hdl* @_mio_aucat_open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
br label %37
24: ; preds = %18
%25 = tail call i64 @_sndio_parsetype(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = tail call i64 @_sndio_parsetype(i8* %19, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = tail call i64 @_sndio_parsetype(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30, %27, %24
%34 = tail call %struct.mio_hdl* @_mio_aucat_open(i8* %19, i32 %1, i32 %2)
br label %37
35: ; preds = %30
%36 = tail call i64 @_sndio_parsetype(i8* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %22, %3, %33
%38 = phi %struct.mio_hdl* [ %34, %33 ], [ null, %3 ], [ %23, %22 ], [ null, %35 ]
ret %struct.mio_hdl* %38
}