#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_MARK;
scalar_t__ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int i = 0;
  glob_t glob_buf;
  if (glob("/sys/class/*", GLOB_MARK, NULL, &glob_buf) != 0) {
    printf("glob failed \n");
    return -1;
  }
  for (i = 0; i < glob_buf.gl_pathc; i++) {
    printf("gl_pathv[i] = %s\n", glob_buf.gl_pathv[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   1040 <glob@plt>
cmp    $0x0,%rax
je     1177 <main+0x57>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <main+0x99>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11b2 <main+0x92>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <main+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0xeb7(%rip),%rdi
xor    %r14d,%r14d
mov    %rsp,%rcx
xor    %edx,%edx
call   1050 <glob@plt>
test   %rax,%rax
je     116f <main+0x3f>
lea    0xebd(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
jmp    11b0 <main+0x80>
cmpl   $0x0,(%rsp)
jle    11b0 <main+0x80>
xor    %r14d,%r14d
lea    0xe8e(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     1190 <main+0x60>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8** }
@.str = [13 x i8] c"/sys/class/*\00"
@GLOB_MARK = global i32 0
@.str.2 = [18 x i8] c"gl_pathv[i] = %s\0A\00"
@str = [13 x i8] c"glob failed \00"
define i32 @main() {
%1 = alloca %struct.TYPE_3__
%2 = bitcast %struct.TYPE_3__* %1 to i8*
%3 = load i32, i32* @GLOB_MARK
%4 = call i64 @glob(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3, i32* null, %struct.TYPE_3__* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %6
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
br label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %24
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %20, %14 ]
%16 = load i8**, i8*** %11
%17 = getelementptr inbounds i8*, i8** %16, i64 %15
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = add nuw nsw i64 %15, 1
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %14, label %24
24: ; preds = %14, %6, %12
%25 = phi i32 [ -1, %12 ], [ 0, %6 ], [ 0, %14 ]
ret i32 %25
}