#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int gl_pathc;
  int /*<<< orphan*/ *gl_pathv;
  int /*<<< orphan*/ member_0;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_APPEND;
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
char *strdup(int /*<<< orphan*/);
int fdelay_get_sysnames(char *result[]) {
  glob_t glob_buf = {
      0,
  };
  int i;
  glob("/sys/bus/zio/devices/fd-*", 0, NULL, &glob_buf);
  glob("/sys/bus/zio/devices/zio-fd-*", GLOB_APPEND, NULL, &glob_buf);
  for (i = 0; i < glob_buf.gl_pathc; i++)
    result[i] = strdup(glob_buf.gl_pathv[i]);
  globfree(&glob_buf);
  return i;
}


x86 assembly (clang, -O0):
<fdelay_get_sysnames>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
lea    0xe9d(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1050 <glob@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x20(%rbp),%rcx
call   1050 <glob@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11cf <fdelay_get_sysnames+0x8f>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1196 <fdelay_get_sysnames+0x56>
lea    -0x20(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdelay_get_sysnames>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xead(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%r15
xor    %esi,%esi
xor    %edx,%edx
mov    %r15,%rcx
call   1040 <glob@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
xor    %edx,%edx
mov    %r15,%rcx
call   1040 <glob@plt>
cmpl   $0x0,(%rsp)
jle    11ae <fdelay_get_sysnames+0x7e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%edi
call   1050 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     1190 <fdelay_get_sysnames+0x60>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32*, i32 }
@.str = [26 x i8] c"/sys/bus/zio/devices/fd-*\00"
@.str.1 = [30 x i8] c"/sys/bus/zio/devices/zio-fd-*\00"
@GLOB_APPEND = global i32 0
define i32 @fdelay_get_sysnames(i8** %0) {
%2 = alloca i8**
%3 = alloca %struct.TYPE_4__
%4 = alloca i32
store i8** %0, i8*** %2
%5 = bitcast %struct.TYPE_4__* %3 to i8*
%6 = call i32 @glob(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, %struct.TYPE_4__* %3)
%7 = load i32, i32* @GLOB_APPEND
%8 = call i32 @glob(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32* null, %struct.TYPE_4__* %3)
store i32 0, i32* %4
br label %9
9: ; preds = %26, %1
%10 = load i32, i32* %4
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 1
%16 = load i32*, i32** %15
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = call i8* @strdup(i32 %20)
%22 = load i8**, i8*** %2
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
store i8* %21, i8** %25
br label %26
26: ; preds = %14
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %9
29: ; preds = %9
%30 = call i32 @globfree(%struct.TYPE_4__* %3)
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32*, i32 }
@.str = [26 x i8] c"/sys/bus/zio/devices/fd-*\00"
@.str.1 = [30 x i8] c"/sys/bus/zio/devices/zio-fd-*\00"
@GLOB_APPEND = global i32 0
define i32 @fdelay_get_sysnames(i8** nocapture writeonly %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = call i32 @glob(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 0, i32* null, %struct.TYPE_4__* %2)
%5 = load i32, i32* @GLOB_APPEND
%6 = call i32 @glob(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32* null, %struct.TYPE_4__* %2)
%7 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = load i32*, i32** %11
%15 = getelementptr inbounds i32, i32* %14, i64 %13
%16 = load i32, i32* %15
%17 = call i8* @strdup(i32 %16)
%18 = getelementptr inbounds i8*, i8** %0, i64 %13
store i8* %17, i8** %18
%19 = add nuw nsw i64 %13, 1
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %12, label %23
23: ; preds = %12
%24 = trunc i64 %19 to i32
br label %25
25: ; preds = %23, %1
%26 = phi i32 [ 0, %1 ], [ %24, %23 ]
%27 = call i32 @globfree(%struct.TYPE_4__* %2)
ret i32 %26
}