#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 str_list {
  int dummy;
};
struct TYPE_4__ {
  size_t gl_pathc;
  int /*<<< orphan*/ *gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_MARK;
int glob(char const *, int /*<<< orphan*/, int (*)(char const *, int),
         TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
scalar_t__ str_list_add(struct str_list *, int /*<<< orphan*/);
int get_paths(struct str_list *paths, const char *pattern) {
  int (*errfunc)(const char *epath, int eerrno) = NULL;
  glob_t threads;
  int err = glob(pattern, GLOB_MARK, errfunc, &threads);
  if (err) {
    return 1;
  }
  for (size_t i = 0; i < threads.gl_pathc; ++i) {
    err += str_list_add(paths, threads.gl_pathv[i]);
  }
  globfree(&threads);
  return err;
}


x86 assembly (clang, -O0):
<get_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e95(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <glob@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     117b <get_paths+0x4b>
movl   $0x1,-0x4(%rbp)
jmp    11d2 <get_paths+0xa2>
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11c3 <get_paths+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <str_list_add@plt>
mov    %rax,%rcx
movslq -0x34(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1183 <get_paths+0x53>
lea    -0x30(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_paths>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%r14
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
xor    %r15d,%r15d
mov    %rsp,%rcx
mov    %rax,%rdi
xor    %edx,%edx
call   1050 <glob@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    1198 <get_paths+0x68>
cmpq   $0x0,(%rsp)
je     118d <get_paths+0x5d>
xor    %ebx,%ebx
xor    %r15d,%r15d
nop
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <str_list_add@plt>
add    %eax,%r15d
add    $0x1,%rbx
cmp    (%rsp),%rbx
jb     1170 <get_paths+0x40>
mov    %rsp,%rdi
call   1030 <globfree@plt>
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.str_list = type { i32 }
%struct.TYPE_4__ = type { i64, i32* }
@GLOB_MARK = global i32 0
define i32 @get_paths(%struct.str_list* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.str_list*
%5 = alloca i8*
%6 = alloca i32 (i8*, i32)*
%7 = alloca %struct.TYPE_4__
%8 = alloca i32
%9 = alloca i64
store %struct.str_list* %0, %struct.str_list** %4
store i8* %1, i8** %5
store i32 (i8*, i32)* null, i32 (i8*, i32)** %6
%10 = load i8*, i8** %5
%11 = load i32, i32* @GLOB_MARK
%12 = load i32 (i8*, i32)*, i32 (i8*, i32)** %6
%13 = call i32 @glob(i8* %10, i32 %11, i32 (i8*, i32)* %12, %struct.TYPE_4__* %7)
store i32 %13, i32* %8
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 1, i32* %3
br label %41
17: ; preds = %2
store i64 0, i64* %9
br label %18
18: ; preds = %35, %17
%19 = load i64, i64* %9
%20 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%21 = load i64, i64* %20
%22 = icmp ult i64 %19, %21
br i1 %22, label %23, label %38
23: ; preds = %18
%24 = load %struct.str_list*, %struct.str_list** %4
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
%26 = load i32*, i32** %25
%27 = load i64, i64* %9
%28 = getelementptr inbounds i32, i32* %26, i64 %27
%29 = load i32, i32* %28
%30 = call i64 @str_list_add(%struct.str_list* %24, i32 %29)
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = add nsw i64 %32, %30
%34 = trunc i64 %33 to i32
store i32 %34, i32* %8
br label %35
35: ; preds = %23
%36 = load i64, i64* %9
%37 = add i64 %36, 1
store i64 %37, i64* %9
br label %18
38: ; preds = %18
%39 = call i32 @globfree(%struct.TYPE_4__* %7)
%40 = load i32, i32* %8
store i32 %40, i32* %3
br label %41
41: ; preds = %38, %16
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.str_list = type { i32 }
%struct.TYPE_4__ = type { i64, i32* }
@GLOB_MARK = global i32 0
define i32 @get_paths(%struct.str_list* %0, i8* %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = load i32, i32* @GLOB_MARK
%6 = call i32 @glob(i8* %1, i32 %5, i32 (i8*, i32)* null, %struct.TYPE_4__* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
br label %17
14: ; preds = %17, %8
%15 = phi i32 [ 0, %8 ], [ %25, %17 ]
%16 = call i32 @globfree(%struct.TYPE_4__* %3)
br label %29
17: ; preds = %12, %17
%18 = phi i64 [ 0, %12 ], [ %26, %17 ]
%19 = phi i32 [ 0, %12 ], [ %25, %17 ]
%20 = load i32*, i32** %13
%21 = getelementptr inbounds i32, i32* %20, i64 %18
%22 = load i32, i32* %21
%23 = call i64 @str_list_add(%struct.str_list* %0, i32 %22)
%24 = trunc i64 %23 to i32
%25 = add i32 %19, %24
%26 = add nuw i64 %18, 1
%27 = load i64, i64* %9
%28 = icmp ult i64 %26, %27
br i1 %28, label %17, label %14
29: ; preds = %2, %14
%30 = phi i32 [ %15, %14 ], [ 1, %2 ]
ret i32 %30
}