#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*/ strncpy(char *, char *, int);
int /*<<< orphan*/ sys_get_audio_devs(char *, int *, char *, int *, int *,
                                      int *, int, int);
void sys_audiodevnumbertoname(int output, int devno, char *name, int namesize) {
  char indevlist[20 * 1024], outdevlist[20 * 1024];
  int nindevs = 0, noutdevs = 0, canmulti, cancallback;
  if (devno < 0) {
    *name = 0;
    return;
  }
  sys_get_audio_devs(indevlist, &nindevs, outdevlist, &noutdevs, &canmulti,
                     &cancallback, 20, 1024);
  if (output && (devno < noutdevs))
    strncpy(name, outdevlist + devno * 1024, namesize);
  else if (!output && (devno < nindevs))
    strncpy(name, indevlist + devno * 1024, namesize);
  else
    *name = 0;
  name[namesize - 1] = 0;
}


x86 assembly (clang, -O0):
<sys_audiodevnumbertoname>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa040,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0xa024(%rbp)
movl   $0x0,-0xa028(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1162 <sys_audiodevnumbertoname+0x42>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1235 <sys_audiodevnumbertoname+0x115>
lea    -0x5020(%rbp),%rdi
lea    -0xa020(%rbp),%rdx
lea    -0xa024(%rbp),%rsi
lea    -0xa028(%rbp),%rcx
lea    -0xa02c(%rbp),%r8
lea    -0xa030(%rbp),%r9
movl   $0x14,(%rsp)
movl   $0x400,0x8(%rsp)
call   1040 <sys_get_audio_devs@plt>
cmpl   $0x0,-0x4(%rbp)
je     11dc <sys_audiodevnumbertoname+0xbc>
mov    -0x8(%rbp),%eax
cmp    -0xa028(%rbp),%eax
jge    11dc <sys_audiodevnumbertoname+0xbc>
mov    -0x10(%rbp),%rdi
lea    -0xa020(%rbp),%rsi
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1224 <sys_audiodevnumbertoname+0x104>
cmpl   $0x0,-0x4(%rbp)
jne    1218 <sys_audiodevnumbertoname+0xf8>
mov    -0x8(%rbp),%eax
cmp    -0xa024(%rbp),%eax
jge    1218 <sys_audiodevnumbertoname+0xf8>
mov    -0x10(%rbp),%rdi
lea    -0x5020(%rbp),%rsi
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
jmp    121f <sys_audiodevnumbertoname+0xff>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1224 <sys_audiodevnumbertoname+0x104>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0xa040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_audiodevnumbertoname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xa018,%rsp
mov    %rdx,%rbx
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
test   %esi,%esi
js     11ce <sys_audiodevnumbertoname+0xae>
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x5010(%rsp),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
push   $0x400
push   $0x14
call   1040 <sys_get_audio_devs@plt>
add    $0x10,%rsp
test   %r15d,%r15d
je     1198 <sys_audiodevnumbertoname+0x78>
cmp    %ebp,(%rsp)
jle    1198 <sys_audiodevnumbertoname+0x78>
shl    $0xa,%ebp
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
jmp    11b4 <sys_audiodevnumbertoname+0x94>
test   %r15d,%r15d
jne    11c1 <sys_audiodevnumbertoname+0xa1>
cmp    %ebp,0x4(%rsp)
jle    11c1 <sys_audiodevnumbertoname+0xa1>
shl    $0xa,%ebp
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x5010,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
jmp    11c4 <sys_audiodevnumbertoname+0xa4>
movb   $0x0,(%rbx)
movslq %r14d,%rax
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
movb   $0x0,(%rbx)
add    $0xa018,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @sys_audiodevnumbertoname(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [20480 x i8]
%10 = alloca [20480 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %11
store i32 0, i32* %12
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i8*, i8** %7
store i8 0, i8* %18
br label %63
19: ; preds = %4
%20 = getelementptr inbounds [20480 x i8], [20480 x i8]* %9, i64 0, i64 0
%21 = getelementptr inbounds [20480 x i8], [20480 x i8]* %10, i64 0, i64 0
%22 = call i32 @sys_get_audio_devs(i8* %20, i32* %11, i8* %21, i32* %12, i32* %13, i32* %14, i32 20, i32 1024)
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %19
%26 = load i32, i32* %6
%27 = load i32, i32* %12
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = load i8*, i8** %7
%31 = getelementptr inbounds [20480 x i8], [20480 x i8]* %10, i64 0, i64 0
%32 = load i32, i32* %6
%33 = mul nsw i32 %32, 1024
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i32, i32* %8
%37 = call i32 @strncpy(i8* %30, i8* %35, i32 %36)
br label %57
38: ; preds = %25, %19
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %54, label %41
41: ; preds = %38
%42 = load i32, i32* %6
%43 = load i32, i32* %11
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i8*, i8** %7
%47 = getelementptr inbounds [20480 x i8], [20480 x i8]* %9, i64 0, i64 0
%48 = load i32, i32* %6
%49 = mul nsw i32 %48, 1024
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i32, i32* %8
%53 = call i32 @strncpy(i8* %46, i8* %51, i32 %52)
br label %56
54: ; preds = %41, %38
%55 = load i8*, i8** %7
store i8 0, i8* %55
br label %56
56: ; preds = %54, %45
br label %57
57: ; preds = %56, %29
%58 = load i8*, i8** %7
%59 = load i32, i32* %8
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %57, %17
ret void
}

LLVM IR (-O2):
define void @sys_audiodevnumbertoname(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [20480 x i8]
%6 = alloca [20480 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = getelementptr inbounds [20480 x i8], [20480 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [20480 x i8], [20480 x i8]* %6, i64 0, i64 0
%13 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%14 = bitcast i32* %8 to i8*
store i32 0, i32* %8
%15 = bitcast i32* %9 to i8*
%16 = bitcast i32* %10 to i8*
%17 = icmp slt i32 %1, 0
br i1 %17, label %44, label %18
18: ; preds = %4
%19 = call i32 @sys_get_audio_devs(i8* %11, i32* %7, i8* %12, i32* %8, i32* %9, i32* %10, i32 20, i32 1024)
%20 = icmp eq i32 %0, 0
%21 = xor i1 %20, true
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, %1
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = shl nsw i32 %1, 10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [20480 x i8], [20480 x i8]* %6, i64 0, i64 %27
%29 = call i32 @strncpy(i8* %2, i8* %28, i32 %3)
br label %40
30: ; preds = %18
%31 = load i32, i32* %7
%32 = icmp sgt i32 %31, %1
%33 = select i1 %20, i1 %32, i1 false
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = shl nsw i32 %1, 10
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [20480 x i8], [20480 x i8]* %5, i64 0, i64 %36
%38 = call i32 @strncpy(i8* %2, i8* %37, i32 %3)
br label %40
39: ; preds = %30
store i8 0, i8* %2
br label %40
40: ; preds = %34, %39, %25
%41 = add nsw i32 %3, -1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %2, i64 %42
br label %44
44: ; preds = %4, %40
%45 = phi i8* [ %43, %40 ], [ %2, %4 ]
store i8 0, i8* %45
ret void
}