#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__ {
  size_t gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_MARK;
scalar_t__ glob(char const *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ printf(char *, char *);
void ls(const char *dir) {
  glob_t gl;
  size_t i;
  if (glob(dir, GLOB_MARK, NULL, &gl) != 0)
    return;
  for (i = 0; i < gl.gl_pathc; i++)
    printf("%s\n", gl.gl_pathv[i]);
  globfree(&gl);
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1050 <glob@plt>
cmp    $0x0,%rax
je     1165 <ls+0x35>
jmp    11ad <ls+0x7d>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a4 <ls+0x74>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116d <ls+0x3d>
lea    -0x18(%rbp),%rdi
call   1030 <globfree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1050 <glob@plt>
test   %rax,%rax
jne    1196 <ls+0x66>
cmpq   $0x0,0x8(%rsp)
je     118c <ls+0x5c>
xor    %ebx,%ebx
lea    0xe9e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    0x8(%rsp),%rbx
jb     1170 <ls+0x40>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i8** }
@GLOB_MARK = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @ls(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_4__
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @GLOB_MARK
%7 = call i64 @glob(i8* %5, i32 %6, i32* null, %struct.TYPE_4__* %3)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
br label %28
10: ; preds = %1
store i64 0, i64* %4
br label %11
11: ; preds = %23, %10
%12 = load i64, i64* %4
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i32 0, i32 1
%18 = load i8**, i8*** %17
%19 = load i64, i64* %4
%20 = getelementptr inbounds i8*, i8** %18, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %16
%24 = load i64, i64* %4
%25 = add i64 %24, 1
store i64 %25, i64* %4
br label %11
26: ; preds = %11
%27 = call i32 @globfree(%struct.TYPE_4__* %3)
br label %28
28: ; preds = %26, %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i8** }
@GLOB_MARK = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @ls(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = bitcast %struct.TYPE_4__* %2 to i8*
%4 = load i32, i32* @GLOB_MARK
%5 = call i64 @glob(i8* %0, i32 %4, i32* null, %struct.TYPE_4__* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %24
7: ; preds = %1
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %7
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %19, %13 ]
%15 = load i8**, i8*** %12
%16 = getelementptr inbounds i8*, i8** %15, i64 %14
%17 = load i8*, i8** %16
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = add nuw i64 %14, 1
%20 = load i64, i64* %8
%21 = icmp ult i64 %19, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %7
%23 = call i32 @globfree(%struct.TYPE_4__* %2)
br label %24
24: ; preds = %1, %22
ret void
}