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

/* Variables and functions */
int GLOB_ABORTED;
int GLOB_NOMATCH;
int GLOB_NOSPACE;
scalar_t__ glob(char const *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int glob_path(const char *pattern, char *buffer) {
  glob_t globbuf;
  int status = 0;
  if (glob(pattern, 0, NULL, &globbuf)) {
    if (status & GLOB_ABORTED)
      printf("GLOB_ABORTED\n");
    if (status & GLOB_NOMATCH)
      printf("GLOB_NOMATCH\n");
    if (status & GLOB_NOSPACE)
      printf("GLOB_NOSPACE\n");
    return 0;
  }
  if (globbuf.gl_pathc == 1) {
    strcpy(buffer, globbuf.gl_pathv[0]);
    status = -1;
  } else {
    printf("Ambiguous input\n");
    status = 0;
  }
  globfree(&globbuf);
  return status;
}


x86 assembly (clang, -O0):
<glob_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x28(%rbp),%rcx
call   1060 <glob@plt>
cmp    $0x0,%rax
je     11e3 <glob_path+0xa3>
mov    -0x2c(%rbp),%eax
mov    0x2e52(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1195 <glob_path+0x55>
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    0x2e51(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b6 <glob_path+0x76>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    0x2e20(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11d7 <glob_path+0x97>
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    122a <glob_path+0xea>
cmpl   $0x1,-0x28(%rbp)
jne    1208 <glob_path+0xc8>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
movl   $0xffffffff,-0x2c(%rbp)
jmp    121b <glob_path+0xdb>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <globfree@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<glob_path>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
xor    %ebx,%ebx
lea    0x8(%rsp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   1060 <glob@plt>
test   %rax,%rax
jne    1194 <glob_path+0x54>
cmpl   $0x1,0x8(%rsp)
jne    117c <glob_path+0x3c>
mov    0x10(%rsp),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    $0xffffffff,%ebx
jmp    118a <glob_path+0x4a>
lea    0xe7d(%rip),%rdi
call   1050 <puts@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32* }
@GLOB_ABORTED = global i32 0
@.str = [14 x i8] c"GLOB_ABORTED\0A\00"
@GLOB_NOMATCH = global i32 0
@.str.1 = [14 x i8] c"GLOB_NOMATCH\0A\00"
@GLOB_NOSPACE = global i32 0
@.str.2 = [14 x i8] c"GLOB_NOSPACE\0A\00"
@.str.3 = [17 x i8] c"Ambiguous input\0A\00"
define i32 @glob_path(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.TYPE_4__
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = call i64 @glob(i8* %8, i32 0, i32* null, %struct.TYPE_4__* %6)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %33
11: ; preds = %2
%12 = load i32, i32* %7
%13 = load i32, i32* @GLOB_ABORTED
%14 = and i32 %12, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = load i32, i32* %7
%20 = load i32, i32* @GLOB_NOMATCH
%21 = and i32 %19, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = load i32, i32* %7
%27 = load i32, i32* @GLOB_NOSPACE
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
store i32 0, i32* %3
br label %49
33: ; preds = %2
%34 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 0
%35 = load i32, i32* %34
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i8*, i8** %5
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %6, i32 0, i32 1
%40 = load i32*, i32** %39
%41 = getelementptr inbounds i32, i32* %40, i64 0
%42 = load i32, i32* %41
%43 = call i32 @strcpy(i8* %38, i32 %42)
store i32 -1, i32* %7
br label %46
44: ; preds = %33
%45 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %7
br label %46
46: ; preds = %44, %37
%47 = call i32 @globfree(%struct.TYPE_4__* %6)
%48 = load i32, i32* %7
store i32 %48, i32* %3
br label %49
49: ; preds = %46, %32
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32* }
@GLOB_ABORTED = global i32 0
@GLOB_NOMATCH = global i32 0
@GLOB_NOSPACE = global i32 0
@str = [16 x i8] c"Ambiguous input\00"
define i32 @glob_path(i8* %0, i8* %1) {
%3 = alloca %struct.TYPE_4__
%4 = bitcast %struct.TYPE_4__* %3 to i8*
%5 = call i64 @glob(i8* %0, i32 0, i32* null, %struct.TYPE_4__* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %3, i64 0, i32 1
%13 = load i32*, i32** %12
%14 = load i32, i32* %13
%15 = call i32 @strcpy(i8* %1, i32 %14)
br label %18
16: ; preds = %7
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
%19 = phi i32 [ -1, %11 ], [ 0, %16 ]
%20 = call i32 @globfree(%struct.TYPE_4__* %3)
br label %21
21: ; preds = %2, %18
%22 = phi i32 [ %19, %18 ], [ 0, %2 ]
ret i32 %22
}