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

/* Variables and functions */
struct sio_hdl *_sio_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 sio_hdl *sio_open(const char *str, unsigned int mode, int nbio) {
  static char devany[] = "default";
  struct sio_hdl *hdl;
  if ((mode & (1 | 2)) == 0)
    return NULL;
  if (str == NULL)
    str = devany;
  if (strcmp(str, devany) == 0 && !_sndio_issetugid()) {
    str = getenv("AUDIODEVICE");
    if (str == NULL)
      str = devany;
  }
  if (strcmp(str, devany) == 0) {
    hdl = _sio_aucat_open("snd/0", mode, nbio);
    if (hdl != NULL)
      return hdl;
    return NULL;
  }
  if (_sndio_parsetype(str, "snd"))
    return _sio_aucat_open(str, mode, nbio);
  if (_sndio_parsetype(str, "rsnd"))
    return NULL;
  do {
  } while (0);
  return NULL;
}


x86 assembly (clang, -O0):
<sio_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    $0x3,%eax
cmp    $0x0,%eax
jne    117e <sio_open+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    12a9 <sio_open+0x159>
cmpq   $0x0,-0x10(%rbp)
jne    1194 <sio_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 <sio_open+0x99>
mov    $0x0,%al
call   1040 <_sndio_issetugid@plt>
cmp    $0x0,%eax
jne    11e9 <sio_open+0x99>
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e4 <sio_open+0x94>
lea    0x2e68(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11e9 <sio_open+0x99>
mov    -0x10(%rbp),%rdi
lea    0x2e54(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123e <sio_open+0xee>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdfc(%rip),%rdi
call   1070 <_sio_aucat_open@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1231 <sio_open+0xe1>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a9 <sio_open+0x159>
movq   $0x0,-0x8(%rbp)
jmp    12a9 <sio_open+0x159>
mov    -0x10(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
je     1270 <sio_open+0x120>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <_sio_aucat_open@plt>
mov    %rax,-0x8(%rbp)
jmp    12a9 <sio_open+0x159>
mov    -0x10(%rbp),%rdi
lea    0xd97(%rip),%rsi
call   1060 <_sndio_parsetype@plt>
cmp    $0x0,%rax
je     1297 <sio_open+0x147>
movq   $0x0,-0x8(%rbp)
jmp    12a9 <sio_open+0x159>
jmp    129c <sio_open+0x14c>
jmp    12a1 <sio_open+0x151>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_open>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
test   $0x3,%r15b
je     1201 <sio_open+0xb1>
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 <sio_open+0x59>
xor    %eax,%eax
call   1040 <_sndio_issetugid@plt>
test   %eax,%eax
jne    11a9 <sio_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     11d6 <sio_open+0x86>
lea    0xe4f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <_sndio_parsetype@plt>
test   %rax,%rax
je     11f2 <sio_open+0xa2>
mov    %rbx,%rdi
jmp    11dd <sio_open+0x8d>
lea    0xe2f(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <_sio_aucat_open@plt>
lea    0xe19(%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.sio_hdl = type { i32 }
@sio_open.devany = internal global [8 x i8] c"default\00"
@.str = [12 x i8] c"AUDIODEVICE\00"
@.str.1 = [6 x i8] c"snd/0\00"
@.str.2 = [4 x i8] c"snd\00"
@.str.3 = [5 x i8] c"rsnd\00"
define %struct.sio_hdl* @sio_open(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.sio_hdl*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sio_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, 3
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
store %struct.sio_hdl* null, %struct.sio_hdl** %4
br label %60
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]* @sio_open.devany, 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]* @sio_open.devany, 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 ([12 x i8], [12 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]* @sio_open.devany, 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]* @sio_open.devany, 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.sio_hdl* @_sio_aucat_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
store %struct.sio_hdl* %37, %struct.sio_hdl** %8
%38 = load %struct.sio_hdl*, %struct.sio_hdl** %8
%39 = icmp ne %struct.sio_hdl* %38, null
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = load %struct.sio_hdl*, %struct.sio_hdl** %8
store %struct.sio_hdl* %41, %struct.sio_hdl** %4
br label %60
42: ; preds = %34
store %struct.sio_hdl* null, %struct.sio_hdl** %4
br label %60
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 %47, label %52
47: ; preds = %43
%48 = load i8*, i8** %5
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = call %struct.sio_hdl* @_sio_aucat_open(i8* %48, i32 %49, i32 %50)
store %struct.sio_hdl* %51, %struct.sio_hdl** %4
br label %60
52: ; preds = %43
%53 = load i8*, i8** %5
%54 = call i64 @_sndio_parsetype(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %52
store %struct.sio_hdl* null, %struct.sio_hdl** %4
br label %60
57: ; preds = %52
br label %58
58: ; preds = %57
br label %59
59: ; preds = %58
store %struct.sio_hdl* null, %struct.sio_hdl** %4
br label %60
60: ; preds = %59, %56, %47, %42, %40, %12
%61 = load %struct.sio_hdl*, %struct.sio_hdl** %4
ret %struct.sio_hdl* %61
}

LLVM IR (-O2):
%struct.sio_hdl = type { i32 }
@sio_open.devany = internal global [8 x i8] c"default\00"
@.str = [12 x i8] c"AUDIODEVICE\00"
@.str.1 = [6 x i8] c"snd/0\00"
@.str.2 = [4 x i8] c"snd\00"
@.str.3 = [5 x i8] c"rsnd\00"
define %struct.sio_hdl* @sio_open(i8* %0, i32 %1, i32 %2) {
%4 = and i32 %1, 3
%5 = icmp eq i32 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = icmp eq i8* %0, null
%8 = select i1 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @sio_open.devany, i64 0, i64 0), i8* %0
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @sio_open.devany, 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 ([12 x i8], [12 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]* @sio_open.devany, 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]* @sio_open.devany, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call %struct.sio_hdl* @_sio_aucat_open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
br label %31
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 %29, label %27
27: ; preds = %24
%28 = tail call %struct.sio_hdl* @_sio_aucat_open(i8* %19, i32 %1, i32 %2)
br label %31
29: ; preds = %24
%30 = tail call i64 @_sndio_parsetype(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %22, %3, %27
%32 = phi %struct.sio_hdl* [ %28, %27 ], [ null, %3 ], [ %23, %22 ], [ null, %29 ]
ret %struct.sio_hdl* %32
}