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

/* Variables and functions */
scalar_t__ realloc(char **, int);
char *strdup(char const *);
int add_entry(const char *name, glob_t *pglob, int *nfound) {
  pglob->gl_pathv = (char **)realloc(
      pglob->gl_pathv, (pglob->gl_pathc + pglob->gl_offs + 2) * sizeof(char *));
  if (pglob->gl_pathv == NULL)
    return 1;
  pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = strdup(name);
  pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL;
  pglob->gl_pathc++;
  (*nfound)++;
  return 0;
}


x86 assembly (clang, -O0):
<add_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x18(%rbp),%rcx
add    0xc(%rcx),%eax
add    $0x2,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    117d <add_entry+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <add_entry+0xc7>
mov    -0x10(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    0xc(%rcx),%ecx
mov    -0x18(%rbp),%rsi
add    0x8(%rsi),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
mov    0xc(%rcx),%ecx
mov    -0x18(%rbp),%rdx
add    0x8(%rdx),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_entry>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rsi),%rdi
mov    0xc(%rsi),%eax
add    0x8(%rsi),%eax
lea    0x10(,%rax,8),%esi
call   1030 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1185 <add_entry+0x65>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strdup@plt>
movslq 0xc(%rbx),%rcx
movslq 0x8(%rbx),%rdx
add    %rdx,%rcx
mov    %rax,(%r12,%rcx,8)
mov    (%rbx),%rax
movslq %ecx,%rcx
movq   $0x0,0x8(%rax,%rcx,8)
lea    0x1(%rdx),%eax
mov    %eax,0x8(%rbx)
addl   $0x1,(%r14)
xor    %eax,%eax
jmp    118a <add_entry+0x6a>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8**, i32, i32 }
define i32 @add_entry(i8* %0, %struct.TYPE_3__* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.TYPE_3__*
%7 = alloca i32*
store i8* %0, i8** %5
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %6
store i32* %2, i32** %7
%8 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i32 0, i32 0
%10 = load i8**, i8*** %9
%11 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %14, i32 0, i32 2
%16 = load i32, i32* %15
%17 = add nsw i32 %13, %16
%18 = add nsw i32 %17, 2
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 8
%21 = trunc i64 %20 to i32
%22 = call i64 @realloc(i8** %10, i32 %21)
%23 = inttoptr i64 %22 to i8**
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
store i8** %23, i8*** %25
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
%28 = load i8**, i8*** %27
%29 = icmp eq i8** %28, null
br i1 %29, label %30, label %31
30: ; preds = %3
store i32 1, i32* %4
br label %66
31: ; preds = %3
%32 = load i8*, i8** %5
%33 = call i8* @strdup(i8* %32)
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 0
%36 = load i8**, i8*** %35
%37 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%38 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %37, i32 0, i32 2
%39 = load i32, i32* %38
%40 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = add nsw i32 %39, %42
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %36, i64 %44
store i8* %33, i8** %45
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 0
%48 = load i8**, i8*** %47
%49 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%50 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%53 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %52, i32 0, i32 1
%54 = load i32, i32* %53
%55 = add nsw i32 %51, %54
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %48, i64 %57
store i8* null, i8** %58
%59 = load %struct.TYPE_3__*, %struct.TYPE_3__** %6
%60 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = add nsw i32 %61, 1
store i32 %62, i32* %60
%63 = load i32*, i32** %7
%64 = load i32, i32* %63
%65 = add nsw i32 %64, 1
store i32 %65, i32* %63
store i32 0, i32* %4
br label %66
66: ; preds = %31, %30
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8**, i32, i32 }
define i32 @add_entry(i8* nocapture %0, %struct.TYPE_3__* nocapture %1, i32* nocapture %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%5 = load i8**, i8*** %4
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
%9 = load i32, i32* %8
%10 = add nsw i32 %9, %7
%11 = shl i32 %10, 3
%12 = add i32 %11, 16
%13 = tail call i64 @realloc(i8** %5, i32 %12)
%14 = inttoptr i64 %13 to i8**
store i8** %14, i8*** %4
%15 = icmp eq i64 %13, 0
br i1 %15, label %30, label %16
16: ; preds = %3
%17 = tail call i8* @strdup(i8* %0)
%18 = load i32, i32* %8
%19 = load i32, i32* %6
%20 = add nsw i32 %19, %18
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %14, i64 %21
store i8* %17, i8** %22
%23 = load i8**, i8*** %4
%24 = add nsw i32 %20, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
store i8* null, i8** %26
%27 = add nsw i32 %19, 1
store i32 %27, i32* %6
%28 = load i32, i32* %2
%29 = add nsw i32 %28, 1
store i32 %29, i32* %2
br label %30
30: ; preds = %3, %16
%31 = phi i32 [ 0, %16 ], [ 1, %3 ]
ret i32 %31
}