#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*/ free(int *);
scalar_t__ procfs_walk(char *, int **, int *);
int *zalloc(int);
int procfs_enum_id(char *path, int **id_arr, int *nids) {
  int *ids, num = 4096;
  if ((ids = zalloc(4096 * sizeof(int))) == NULL) {
    return (-1);
  }
  if (procfs_walk(path, &ids, &num) != 0) {
    if (ids != NULL) {
      free(ids);
    }
    return (-1);
  }
  *id_arr = ids;
  *nids = num;
  return (0);
}


x86 assembly (clang, -O0):
<procfs_enum_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1000,-0x2c(%rbp)
mov    $0x4000,%edi
call   1050 <zalloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    116f <procfs_enum_id+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <procfs_enum_id+0x95>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1040 <procfs_walk@plt>
cmp    $0x0,%rax
je     11aa <procfs_enum_id+0x7a>
cmpq   $0x0,-0x28(%rbp)
je     119e <procfs_enum_id+0x6e>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c5 <procfs_enum_id+0x95>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<procfs_enum_id>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x1000,0xc(%rsp)
mov    $0x4000,%edi
call   1050 <zalloc@plt>
mov    %rax,0x10(%rsp)
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1198 <procfs_enum_id+0x68>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <procfs_walk@plt>
mov    0x10(%rsp),%rdi
test   %rax,%rax
je     118c <procfs_enum_id+0x5c>
test   %rdi,%rdi
je     1198 <procfs_enum_id+0x68>
call   1030 <free@plt>
jmp    1198 <procfs_enum_id+0x68>
mov    %rdi,(%r15)
mov    0xc(%rsp),%eax
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @procfs_enum_id(i8* %0, i32** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32** %1, i32*** %6
store i32* %2, i32** %7
store i32 4096, i32* %9
%10 = call i32* @zalloc(i32 16384)
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %29
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @procfs_walk(i8* %14, i32** %8, i32* %9)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = load i32*, i32** %8
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32*, i32** %8
%22 = call i32 @free(i32* %21)
br label %23
23: ; preds = %20, %17
store i32 -1, i32* %4
br label %29
24: ; preds = %13
%25 = load i32*, i32** %8
%26 = load i32**, i32*** %6
store i32* %25, i32** %26
%27 = load i32, i32* %9
%28 = load i32*, i32** %7
store i32 %27, i32* %28
store i32 0, i32* %4
br label %29
29: ; preds = %24, %23, %12
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @procfs_enum_id(i8* %0, i32** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = bitcast i32** %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4096, i32* %5
%8 = tail call i32* @zalloc(i32 16384)
store i32* %8, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %20, label %10
10: ; preds = %3
%11 = call i64 @procfs_walk(i8* %0, i32** %4, i32* %5)
%12 = icmp eq i64 %11, 0
%13 = load i32*, i32** %4
br i1 %12, label %18, label %14
14: ; preds = %10
%15 = icmp eq i32* %13, null
br i1 %15, label %20, label %16
16: ; preds = %14
%17 = call i32 @free(i32* %13)
br label %20
18: ; preds = %10
store i32* %13, i32** %1
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %20
20: ; preds = %14, %16, %3, %18
%21 = phi i32 [ 0, %18 ], [ -1, %3 ], [ -1, %16 ], [ -1, %14 ]
ret i32 %21
}