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

/* Type definitions */
struct TYPE_6__ {
  int gl_offs;
};
typedef TYPE_1__ glob_t;
typedef int /*<<< orphan*/ gl;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ GLOB_ABORTED;
int GLOB_ALTDIRFUNC;
int GLOB_DOOFFS;
int GLOB_ERR;
scalar_t__ GLOB_NOMATCH;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ glob(char *, int, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ init_glob_altdirfuncs(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ mtrace();
int /*<<< orphan*/ muntrace();
int /*<<< orphan*/ puts(char *);
int do_test(void) {
  mtrace();
  glob_t gl;
  memset(&gl, 0, sizeof(gl));
  init_glob_altdirfuncs(&gl);
  if (glob("dir/*able/*", GLOB_ERR | GLOB_ALTDIRFUNC, NULL, &gl) !=
      GLOB_ABORTED) {
    puts("glob did not fail with GLOB_ABORTED");
    exit(EXIT_FAILURE);
  }
  globfree(&gl);
  memset(&gl, 0, sizeof(gl));
  init_glob_altdirfuncs(&gl);
  gl.gl_offs = 3;
  if (glob("dir2/*", GLOB_DOOFFS, NULL, &gl) != GLOB_NOMATCH) {
    puts("glob did not fail with GLOB_NOMATCH");
    exit(EXIT_FAILURE);
  }
  globfree(&gl);
  muntrace();
  return 0;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <mtrace@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x8(%rbp),%rdi
call   1080 <init_glob_altdirfuncs@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e20(%rip),%rax
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x8(%rbp),%rcx
call   1090 <glob@plt>
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
je     11f8 <do_test+0x78>
lea    0xe27(%rip),%rdi
call   1040 <puts@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1030 <globfree@plt>
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
lea    -0x8(%rbp),%rdi
call   1080 <init_glob_altdirfuncs@plt>
movl   $0x3,-0x8(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%esi
lea    0xdff(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x8(%rbp),%rcx
call   1090 <glob@plt>
mov    0x2dab(%rip),%rcx
cmp    (%rcx),%rax
je     1268 <do_test+0xe8>
lea    0xde2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1030 <globfree@plt>
mov    $0x0,%al
call   1060 <muntrace@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <mtrace@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1080 <init_glob_altdirfuncs@plt>
mov    0x2e39(%rip),%rax
mov    0x2e22(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe3f(%rip),%rdi
xor    %edx,%edx
mov    %rbx,%rcx
call   1090 <glob@plt>
mov    0x2de6(%rip),%rcx
cmp    (%rcx),%rax
jne    1242 <do_test+0xc2>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <globfree@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1080 <init_glob_altdirfuncs@plt>
movl   $0x3,0x8(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%esi
lea    0xe1d(%rip),%rdi
xor    %edx,%edx
mov    %rbx,%rcx
call   1090 <glob@plt>
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%rax
jne    124b <do_test+0xcb>
lea    0x8(%rsp),%rdi
call   1030 <globfree@plt>
xor    %eax,%eax
call   1060 <muntrace@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xdc3(%rip),%rdi
jmp    1252 <do_test+0xd2>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_6__ = type { i32 }
@.str = [12 x i8] c"dir/*able/*\00"
@GLOB_ERR = global i32 0
@GLOB_ALTDIRFUNC = global i32 0
@GLOB_ABORTED = global i64 0
@.str.1 = [36 x i8] c"glob did not fail with GLOB_ABORTED\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"dir2/*\00"
@GLOB_DOOFFS = global i32 0
@GLOB_NOMATCH = global i64 0
@.str.3 = [36 x i8] c"glob did not fail with GLOB_NOMATCH\00"
define i32 @do_test() {
%1 = alloca %struct.TYPE_6__
%2 = call i32 (...) @mtrace()
%3 = call i32 @memset(%struct.TYPE_6__* %1, i32 0, i32 4)
%4 = call i32 @init_glob_altdirfuncs(%struct.TYPE_6__* %1)
%5 = load i32, i32* @GLOB_ERR
%6 = load i32, i32* @GLOB_ALTDIRFUNC
%7 = or i32 %5, %6
%8 = call i64 @glob(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7, i32* null, %struct.TYPE_6__* %1)
%9 = load i64, i64* @GLOB_ABORTED
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = call i32 @globfree(%struct.TYPE_6__* %1)
%17 = call i32 @memset(%struct.TYPE_6__* %1, i32 0, i32 4)
%18 = call i32 @init_glob_altdirfuncs(%struct.TYPE_6__* %1)
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i32 0, i32 0
store i32 3, i32* %19
%20 = load i32, i32* @GLOB_DOOFFS
%21 = call i64 @glob(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32* null, %struct.TYPE_6__* %1)
%22 = load i64, i64* @GLOB_NOMATCH
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %28
24: ; preds = %15
%25 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
%29 = call i32 @globfree(%struct.TYPE_6__* %1)
%30 = call i32 (...) @muntrace()
ret i32 0
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i32 }
@.str = [12 x i8] c"dir/*able/*\00"
@GLOB_ERR = global i32 0
@GLOB_ALTDIRFUNC = global i32 0
@GLOB_ABORTED = global i64 0
@.str.1 = [36 x i8] c"glob did not fail with GLOB_ABORTED\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [7 x i8] c"dir2/*\00"
@GLOB_DOOFFS = global i32 0
@GLOB_NOMATCH = global i64 0
@.str.3 = [36 x i8] c"glob did not fail with GLOB_NOMATCH\00"
define i32 @do_test() {
%1 = alloca %struct.TYPE_6__
%2 = tail call i32 (...) @mtrace()
%3 = bitcast %struct.TYPE_6__* %1 to i8*
%4 = call i32 @memset(%struct.TYPE_6__* %1, i32 0, i32 4)
%5 = call i32 @init_glob_altdirfuncs(%struct.TYPE_6__* %1)
%6 = load i32, i32* @GLOB_ERR
%7 = load i32, i32* @GLOB_ALTDIRFUNC
%8 = or i32 %7, %6
%9 = call i64 @glob(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8, i32* null, %struct.TYPE_6__* %1)
%10 = load i64, i64* @GLOB_ABORTED
%11 = icmp eq i64 %9, %10
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
%17 = call i32 @globfree(%struct.TYPE_6__* %1)
%18 = call i32 @memset(%struct.TYPE_6__* %1, i32 0, i32 4)
%19 = call i32 @init_glob_altdirfuncs(%struct.TYPE_6__* %1)
%20 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %1, i64 0, i32 0
store i32 3, i32* %20
%21 = load i32, i32* @GLOB_DOOFFS
%22 = call i64 @glob(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32* null, %struct.TYPE_6__* %1)
%23 = load i64, i64* @GLOB_NOMATCH
%24 = icmp eq i64 %22, %23
br i1 %24, label %29, label %25
25: ; preds = %16
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %16
%30 = call i32 @globfree(%struct.TYPE_6__* %1)
%31 = call i32 (...) @muntrace()
ret i32 0
}