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


x86 assembly (clang, -O0):
<sys_audiodevnumbertoname>:
push   %rbp
mov    %rsp,%rbp
sub    $0xcd0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0xca4(%rbp)
movl   $0x0,-0xca8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1162 <sys_audiodevnumbertoname+0x42>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1231 <sys_audiodevnumbertoname+0x111>
lea    -0x660(%rbp),%rdi
lea    -0xca0(%rbp),%rdx
lea    -0xca4(%rbp),%rsi
lea    -0xca8(%rbp),%rcx
lea    -0xcb0(%rbp),%r8
lea    -0xcb4(%rbp),%r9
movl   $0x14,(%rsp)
movl   $0x50,0x8(%rsp)
call   1040 <sys_get_audio_devs@plt>
cmpl   $0x0,-0x4(%rbp)
je     11da <sys_audiodevnumbertoname+0xba>
mov    -0x8(%rbp),%eax
cmp    -0xca8(%rbp),%eax
jge    11da <sys_audiodevnumbertoname+0xba>
mov    -0x10(%rbp),%rdi
lea    -0xca0(%rbp),%rsi
imul   $0x50,-0x8(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
jmp    1220 <sys_audiodevnumbertoname+0x100>
cmpl   $0x0,-0x4(%rbp)
jne    1214 <sys_audiodevnumbertoname+0xf4>
mov    -0x8(%rbp),%eax
cmp    -0xca4(%rbp),%eax
jge    1214 <sys_audiodevnumbertoname+0xf4>
mov    -0x10(%rbp),%rdi
lea    -0x660(%rbp),%rsi
imul   $0x50,-0x8(%rbp),%eax
cltq
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
jmp    121b <sys_audiodevnumbertoname+0xfb>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1220 <sys_audiodevnumbertoname+0x100>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0xcd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_audiodevnumbertoname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xc98,%rsp
mov    %rdx,%rbx
movl   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
test   %esi,%esi
js     11d1 <sys_audiodevnumbertoname+0xb1>
mov    %ecx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x650(%rsp),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
push   $0x50
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    $0x4,%ebp
lea    0x0(%rbp,%rbp,4),%eax
cltq
lea    (%rsp,%rax,1),%rsi
add    $0x10,%rsi
jmp    11b7 <sys_audiodevnumbertoname+0x97>
test   %r15d,%r15d
jne    11c4 <sys_audiodevnumbertoname+0xa4>
cmp    %ebp,0x4(%rsp)
jle    11c4 <sys_audiodevnumbertoname+0xa4>
shl    $0x4,%ebp
lea    0x0(%rbp,%rbp,4),%eax
cltq
lea    (%rsp,%rax,1),%rsi
add    $0x650,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
jmp    11c7 <sys_audiodevnumbertoname+0xa7>
movb   $0x0,(%rbx)
movslq %r14d,%rax
add    %rax,%rbx
add    $0xffffffffffffffff,%rbx
movb   $0x0,(%rbx)
add    $0xc98,%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 [1600 x i8]
%10 = alloca [1600 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = 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
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = load i8*, i8** %7
store i8 0, i8* %19
br label %64
20: ; preds = %4
%21 = getelementptr inbounds [1600 x i8], [1600 x i8]* %9, i64 0, i64 0
%22 = getelementptr inbounds [1600 x i8], [1600 x i8]* %10, i64 0, i64 0
%23 = call i32 @sys_get_audio_devs(i8* %21, i32* %11, i8* %22, i32* %12, i32* %14, i32* %15, i32 20, i32 80)
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %39
26: ; preds = %20
%27 = load i32, i32* %6
%28 = load i32, i32* %12
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = getelementptr inbounds [1600 x i8], [1600 x i8]* %10, i64 0, i64 0
%33 = load i32, i32* %6
%34 = mul nsw i32 %33, 80
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i32, i32* %8
%38 = call i32 @strncpy(i8* %31, i8* %36, i32 %37)
br label %58
39: ; preds = %26, %20
%40 = load i32, i32* %5
%41 = icmp ne i32 %40, 0
br i1 %41, label %55, label %42
42: ; preds = %39
%43 = load i32, i32* %6
%44 = load i32, i32* %11
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i8*, i8** %7
%48 = getelementptr inbounds [1600 x i8], [1600 x i8]* %9, i64 0, i64 0
%49 = load i32, i32* %6
%50 = mul nsw i32 %49, 80
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = load i32, i32* %8
%54 = call i32 @strncpy(i8* %47, i8* %52, i32 %53)
br label %57
55: ; preds = %42, %39
%56 = load i8*, i8** %7
store i8 0, i8* %56
br label %57
57: ; preds = %55, %46
br label %58
58: ; preds = %57, %30
%59 = load i8*, i8** %7
%60 = load i32, i32* %8
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8 0, i8* %63
br label %64
64: ; preds = %58, %18
ret void
}

LLVM IR (-O2):
define void @sys_audiodevnumbertoname(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [1600 x i8]
%6 = alloca [1600 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = getelementptr inbounds [1600 x i8], [1600 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [1600 x i8], [1600 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 80)
%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 = mul nsw i32 %1, 80
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1600 x i8], [1600 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 = mul nsw i32 %1, 80
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1600 x i8], [1600 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
}