#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int BUFSIZ;
int count_cpus();
char **malloc(int);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
scalar_t__ snprintf(char *, int, char *, int);
char *strdup(char *);
char **listAliases() {
  int cpu_count = count_cpus();
  if (cpu_count < 0)
    return NULL;
  char **output = malloc(sizeof(char *) * (cpu_count + 1));
  memset(output, 0, sizeof(char *) * (cpu_count + 1));
  int i;
  char buf[BUFSIZ];
  for (i = 0; i < cpu_count; i++) {
    if (snprintf(buf, sizeof(buf), "cpu%d", i))
      output[i] = strdup(buf);
  };
  return output;
}


x86 assembly (clang, -O0):
<listAliases>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x0,%al
call   1040 <count_cpus@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1179 <listAliases+0x29>
movq   $0x0,-0x8(%rbp)
jmp    1245 <listAliases+0xf5>
mov    -0xc(%rbp),%ecx
mov    %ecx,%eax
lea    0x8(,%rax,8),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    %ecx,%eax
lea    0x8(,%rax,8),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1236 <listAliases+0xe6>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x1c(%rbp),%ecx
lea    0xe04(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x0,%rax
je     1223 <listAliases+0xd3>
mov    -0x38(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1228 <listAliases+0xd8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <listAliases+0x8c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listAliases>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <count_cpus@plt>
test   %eax,%eax
js     1208 <listAliases+0xb8>
mov    %eax,%r12d
lea    0x8(,%r12,8),%ebx
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
mov    %rsp,-0x38(%rbp)
mov    0x2e41(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r13
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
test   %r12d,%r12d
je     1200 <listAliases+0xb0>
mov    %r12d,%r14d
xor    %ebx,%ebx
lea    0xe3c(%rip),%r12
jmp    11d9 <listAliases+0x89>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1200 <listAliases+0xb0>
mov    %r13,%rdi
mov    %r15d,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1030 <snprintf@plt>
test   %rax,%rax
je     11d0 <listAliases+0x80>
mov    %r13,%rdi
call   1070 <strdup@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,(%rcx,%rbx,8)
jmp    11d0 <listAliases+0x80>
mov    -0x38(%rbp),%rsp
mov    -0x30(%rbp),%rbx
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [6 x i8] c"cpu%d\00"
define i8** @listAliases() {
%1 = alloca i8**
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = call i32 (...) @count_cpus()
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i8** null, i8*** %1
br label %51
11: ; preds = %0
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i8** @malloc(i32 %16)
store i8** %17, i8*** %3
%18 = load i8**, i8*** %3
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 8, %21
%23 = trunc i64 %22 to i32
%24 = call i32 @memset(i8** %18, i32 0, i32 %23)
%25 = load i32, i32* @BUFSIZ
%26 = zext i32 %25 to i64
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %5
%28 = alloca i8, i64 %26
store i64 %26, i64* %6
store i32 0, i32* %4
br label %29
29: ; preds = %45, %11
%30 = load i32, i32* %4
%31 = load i32, i32* %2
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %48
33: ; preds = %29
%34 = trunc i64 %26 to i32
%35 = load i32, i32* %4
%36 = call i64 @snprintf(i8* %28, i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = call i8* @strdup(i8* %28)
%40 = load i8**, i8*** %3
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
br label %44
44: ; preds = %38, %33
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %29
48: ; preds = %29
%49 = load i8**, i8*** %3
store i8** %49, i8*** %1
%50 = load i8*, i8** %5
br label %51
51: ; preds = %48, %10
%52 = load i8**, i8*** %1
ret i8** %52
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [6 x i8] c"cpu%d\00"
define i8** @listAliases() {
%1 = tail call i32 (...) @count_cpus()
%2 = icmp slt i32 %1, 0
br i1 %2, label %27, label %3
3: ; preds = %0
%4 = shl i32 %1, 3
%5 = add i32 %4, 8
%6 = tail call i8** @malloc(i32 %5)
%7 = tail call i32 @memset(i8** %6, i32 0, i32 %5)
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = tail call i8* @llvm.stacksave()
%11 = alloca i8, i64 %9
%12 = icmp eq i32 %1, 0
br i1 %12, label %26, label %13
13: ; preds = %3
%14 = zext i32 %1 to i64
br label %15
15: ; preds = %13, %23
%16 = phi i64 [ 0, %13 ], [ %24, %23 ]
%17 = trunc i64 %16 to i32
%18 = call i64 @snprintf(i8* %11, i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = call i8* @strdup(i8* %11)
%22 = getelementptr inbounds i8*, i8** %6, i64 %16
store i8* %21, i8** %22
br label %23
23: ; preds = %15, %20
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, %14
br i1 %25, label %26, label %15
26: ; preds = %23, %3
br label %27
27: ; preds = %0, %26
%28 = phi i8** [ %6, %26 ], [ null, %0 ]
ret i8** %28
}