#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 */
#define GLOB_ABORTED 130
#define GLOB_NOMATCH 129
#define GLOB_NOSPACE 128
int glob(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int i;
  glob_t g;
  switch (glob(argv[1], NULL, NULL, &g)) {
  case GLOB_NOSPACE:
    printf("ran out of memory\n");
    break;
  case GLOB_ABORTED:
    printf("read error\n");
    break;
  case GLOB_NOMATCH:
    printf("no matches found\n");
    break;
  default:
    for (i = 0; i < g.gl_pathc; i++) {
      printf("%s\n", g.gl_pathv[i]);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x28(%rbp),%rcx
mov    %rdx,%rsi
call   1040 <glob@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
sub    $0x80,%eax
je     1189 <main+0x69>
jmp    1163 <main+0x43>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     11af <main+0x8f>
jmp    1176 <main+0x56>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
je     119c <main+0x7c>
jmp    11c2 <main+0xa2>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <main+0xe2>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <main+0xe2>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1202 <main+0xe2>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11fd <main+0xdd>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c9 <main+0xa9>
jmp    1202 <main+0xe2>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x8(%rsi),%rdi
mov    %rsp,%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1040 <glob@plt>
add    $0xffffff80,%eax
cmp    $0x3,%eax
jae    1154 <main+0x34>
cltq
lea    0xeea(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1030 <puts@plt>
jmp    117b <main+0x5b>
cmpl   $0x0,(%rsp)
jle    117b <main+0x5b>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rdi
call   1030 <puts@plt>
add    $0x1,%rbx
movslq (%rsp),%rax
cmp    %rax,%rbx
jl     1160 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i8** }
@.str = [19 x i8] c"ran out of memory\0A\00"
@.str.1 = [12 x i8] c"read error\0A\00"
@.str.2 = [18 x i8] c"no matches found\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.TYPE_3__
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @glob(i8* %10, i32* null, i32* null, %struct.TYPE_3__* %7)
switch i32 %11, label %18 [
i32 128, label %12
i32 130, label %14
i32 129, label %16
]
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %36
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %36
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %36
18: ; preds = %2
store i32 0, i32* %6
br label %19
19: ; preds = %32, %18
%20 = load i32, i32* %6
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 0
%22 = load i32, i32* %21
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %7, i32 0, i32 1
%26 = load i8**, i8*** %25
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %19
35: ; preds = %19
br label %36
36: ; preds = %35, %16, %14, %12
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i8** }
@str = [17 x i8] c"no matches found\00"
@str.4 = [11 x i8] c"read error\00"
@str.5 = [18 x i8] c"ran out of memory\00"
@reltable.main = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.5 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @str to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @str.4 to i64), i64 ptrtoint ([3 x i32]* @reltable.main to i64)) to i32)]
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_3__
%4 = bitcast %struct.TYPE_3__* %3 to i8*
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @glob(i8* %6, i32* null, i32* null, %struct.TYPE_3__* %3)
%8 = add i32 %7, -128
%9 = icmp ult i32 %8, 3
br i1 %9, label %26, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 1
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %22, %16 ]
%18 = load i8**, i8*** %15
%19 = getelementptr inbounds i8*, i8** %18, i64 %17
%20 = load i8*, i8** %19
%21 = call i32 @puts(i8* dereferenceable(1) %20)
%22 = add nuw nsw i64 %17, 1
%23 = load i32, i32* %11
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %16, label %31
26: ; preds = %2
%27 = sext i32 %8 to i64
%28 = shl i64 %27, 2
%29 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.main to i8*), i64 %28)
%30 = call i32 @puts(i8* dereferenceable(1) %29)
br label %31
31: ; preds = %16, %26, %10
ret i32 0
}