#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 */
typedef scalar_t__ pid_t;
struct TYPE_4__ {
  size_t gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *, TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void run_dir(const char *dir) {
  char pat[strlen(dir) + 3];
  sprintf(pat, "%s/*", dir);
  glob_t globbuf;
  if (glob(pat, 0, NULL, &globbuf))
    return;
  for (size_t i = 0; i < globbuf.gl_pathc; i++) {
    char *path = globbuf.gl_pathv[i];
    if (access(path, X_OK) < 0)
      continue;
    pid_t pid = fork();
    if (pid < 0) {
      fputs("autoupdater: warning: failed to fork: %m", stderr);
      continue;
    }
    if (pid == 0) {
      execl(path, path, (char *)NULL);
      exit(EXIT_FAILURE);
    }
    int wstatus;
    if (waitpid(pid, &wstatus, 0) != pid) {
      fprintf(stderr,
              "autoupdater: warning: failed waiting for child %d corresponding "
              "to %s: ",
              pid, path);
      perror(NULL);
    } else if (!WIFEXITED(wstatus)) {
      fprintf(stderr,
              "autoupdater: warning: execution of %s exited abnormally\n",
              path);
    } else if (WEXITSTATUS(wstatus)) {
      fprintf(
          stderr,
          "autoupdater: warning: execution of %s exited with status code %d\n",
          path, WEXITSTATUS(wstatus));
    }
  }
  globfree(&globbuf);
}


x86 assembly (clang, -O0):
<run_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x3,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    0xdda(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x58(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x28(%rbp),%rcx
call   10c0 <glob@plt>
cmp    $0x0,%rax
je     1254 <run_dir+0x74>
movl   $0x1,-0x2c(%rbp)
jmp    13e0 <run_dir+0x200>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    13d0 <run_dir+0x1f0>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
jge    129b <run_dir+0xbb>
jmp    13bf <run_dir+0x1df>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jge    12cb <run_dir+0xeb>
mov    0x2d20(%rip),%rax
mov    (%rax),%esi
lea    0xd44(%rip),%rdi
call   1050 <fputs@plt>
jmp    13bf <run_dir+0x1df>
cmpq   $0x0,-0x48(%rbp)
jne    12f5 <run_dir+0x115>
mov    -0x40(%rbp),%rdi
mov    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <execl@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x48(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    -0x48(%rbp),%rax
je     133b <run_dir+0x15b>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xd08(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <perror@plt>
jmp    13ba <run_dir+0x1da>
mov    -0x4c(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    136c <run_dir+0x18c>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    13b5 <run_dir+0x1d5>
mov    -0x4c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     13b0 <run_dir+0x1d0>
mov    0x2c54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x4c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
lea    0xd06(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    13b5 <run_dir+0x1d5>
jmp    13ba <run_dir+0x1da>
jmp    13bf <run_dir+0x1df>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    125c <run_dir+0x7c>
lea    -0x28(%rbp),%rdi
call   1030 <globfree@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
add    $0x3,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xdec(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   10d0 <sprintf@plt>
lea    -0x40(%rbp),%rcx
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <glob@plt>
test   %rax,%rax
jne    133d <run_dir+0x15d>
cmpq   $0x0,-0x40(%rbp)
je     1334 <run_dir+0x154>
mov    0x2d9e(%rip),%r14
mov    0x2d87(%rip),%rbx
xor    %r12d,%r12d
jmp    127c <run_dir+0x9c>
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx),%esi
lea    0xd9c(%rip),%rdi
call   1050 <fputs@plt>
add    $0x1,%r12
cmp    -0x40(%rbp),%r12
jae    1334 <run_dir+0x154>
mov    -0x38(%rbp),%rax
mov    (%rax,%r12,8),%r13
mov    (%r14),%esi
mov    %r13,%rdi
call   1090 <access@plt>
test   %rax,%rax
js     126e <run_dir+0x8e>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     1260 <run_dir+0x80>
je     134c <run_dir+0x16c>
mov    %rax,%r15
mov    %rax,%rdi
lea    -0x2c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    %r15,%rax
jne    1312 <run_dir+0x132>
mov    -0x2c(%rbp),%edi
call   10b0 <WIFEXITED@plt>
test   %eax,%eax
je     12fa <run_dir+0x11a>
mov    -0x2c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
test   %eax,%eax
je     126e <run_dir+0x8e>
mov    (%rbx),%r15d
mov    -0x2c(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %r15d,%edi
lea    0xdc6(%rip),%rsi
mov    %r13,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    126e <run_dir+0x8e>
mov    (%rbx),%edi
lea    0xd73(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    126e <run_dir+0x8e>
mov    (%rbx),%edi
lea    0xd13(%rip),%rsi
mov    %r15,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   10a0 <perror@plt>
jmp    126e <run_dir+0x8e>
lea    -0x40(%rbp),%rdi
call   1030 <globfree@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r13,%rsi
xor    %edx,%edx
call   10f0 <execl@plt>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64, i8** }
@.str = [5 x i8] c"%s/*\00"
@X_OK = global i32 0
@.str.1 = [41 x i8] c"autoupdater: warning: failed to fork: %m\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [72 x i8] c"autoupdater: warning: failed waiting for child %d corresponding to %s: \00"
@.str.3 = [57 x i8] c"autoupdater: warning: execution of %s exited abnormally\0A\00"
@.str.4 = [66 x i8] c"autoupdater: warning: execution of %s exited with status code %d\0A\00"
define void @run_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.TYPE_4__
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 3
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %3
%16 = alloca i8, i64 %14
store i64 %14, i64* %4
%17 = load i8*, i8** %2
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i64 @glob(i8* %16, i32 0, i32* null, %struct.TYPE_4__* %5)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %1
store i32 1, i32* %6
br label %93
22: ; preds = %1
store i64 0, i64* %7
br label %23
23: ; preds = %88, %22
%24 = load i64, i64* %7
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 0
%26 = load i64, i64* %25
%27 = icmp ult i64 %24, %26
br i1 %27, label %28, label %91
28: ; preds = %23
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %5, i32 0, i32 1
%30 = load i8**, i8*** %29
%31 = load i64, i64* %7
%32 = getelementptr inbounds i8*, i8** %30, i64 %31
%33 = load i8*, i8** %32
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = load i32, i32* @X_OK
%36 = call i64 @access(i8* %34, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %28
br label %88
39: ; preds = %28
%40 = call i64 (...) @fork()
store i64 %40, i64* %9
%41 = load i64, i64* %9
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %88
46: ; preds = %39
%47 = load i64, i64* %9
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i8*, i8** %8
%51 = load i8*, i8** %8
%52 = call i32 @execl(i8* %50, i8* %51, i8* null)
%53 = load i32, i32* @EXIT_FAILURE
%54 = call i32 @exit(i32 %53)
unreachable
55: ; preds = %46
%56 = load i64, i64* %9
%57 = call i64 @waitpid(i64 %56, i32* %10, i32 0)
%58 = load i64, i64* %9
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %67
60: ; preds = %55
%61 = load i32, i32* @stderr
%62 = load i64, i64* %9
%63 = inttoptr i64 %62 to i8*
%64 = load i8*, i8** %8
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %64)
%66 = call i32 @perror(i32* null)
br label %87
67: ; preds = %55
%68 = load i32, i32* %10
%69 = call i32 @WIFEXITED(i32 %68)
%70 = icmp ne i32 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = load i8*, i8** %8
%74 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %73)
br label %86
75: ; preds = %67
%76 = load i32, i32* %10
%77 = call i32 @WEXITSTATUS(i32 %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %85
79: ; preds = %75
%80 = load i32, i32* @stderr
%81 = load i8*, i8** %8
%82 = load i32, i32* %10
%83 = call i32 @WEXITSTATUS(i32 %82)
%84 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %81, i32 %83)
br label %85
85: ; preds = %79, %75
br label %86
86: ; preds = %85, %71
br label %87
87: ; preds = %86, %60
br label %88
88: ; preds = %87, %43, %38
%89 = load i64, i64* %7
%90 = add i64 %89, 1
store i64 %90, i64* %7
br label %23
91: ; preds = %23
%92 = call i32 @globfree(%struct.TYPE_4__* %5)
store i32 0, i32* %6
br label %93
93: ; preds = %91, %21
%94 = load i8*, i8** %3
%95 = load i32, i32* %6
switch i32 %95, label %97 [
i32 0, label %96
i32 1, label %96
]
96: ; preds = %93, %93
ret void
97: ; preds = %93
unreachable
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i64, i8** }
@.str = [5 x i8] c"%s/*\00"
@X_OK = global i32 0
@.str.1 = [41 x i8] c"autoupdater: warning: failed to fork: %m\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [72 x i8] c"autoupdater: warning: failed waiting for child %d corresponding to %s: \00"
@.str.3 = [57 x i8] c"autoupdater: warning: execution of %s exited abnormally\0A\00"
@.str.4 = [66 x i8] c"autoupdater: warning: execution of %s exited with status code %d\0A\00"
define void @run_dir(i8* %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca i32
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 3
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = bitcast %struct.TYPE_4__* %2 to i8*
%10 = call i64 @glob(i8* %7, i32 0, i32* null, %struct.TYPE_4__* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %70
12: ; preds = %1
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%18 = bitcast i32* %3 to i8*
br label %21
19: ; preds = %66, %12
%20 = call i32 @globfree(%struct.TYPE_4__* %2)
br label %70
21: ; preds = %16, %66
%22 = phi i64 [ 0, %16 ], [ %67, %66 ]
%23 = load i8**, i8*** %17
%24 = getelementptr inbounds i8*, i8** %23, i64 %22
%25 = load i8*, i8** %24
%26 = load i32, i32* @X_OK
%27 = call i64 @access(i8* %25, i32 %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %66, label %29
29: ; preds = %21
%30 = call i64 (...) @fork()
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = call i32 @fputs(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %66
35: ; preds = %29
%36 = icmp eq i64 %30, 0
br i1 %36, label %37, label %41
37: ; preds = %35
%38 = call i32 @execl(i8* %25, i8* %25, i8* null)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %35
%42 = call i64 @waitpid(i64 %30, i32* %3, i32 0)
%43 = icmp eq i64 %42, %30
br i1 %43, label %49, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = inttoptr i64 %30 to i8*
%47 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %46, i8* %25)
%48 = call i32 @perror(i32* null)
br label %65
49: ; preds = %41
%50 = load i32, i32* %3
%51 = call i32 @WIFEXITED(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %65
56: ; preds = %49
%57 = load i32, i32* %3
%58 = call i32 @WEXITSTATUS(i32 %57)
%59 = icmp eq i32 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %56
%61 = load i32, i32* @stderr
%62 = load i32, i32* %3
%63 = call i32 @WEXITSTATUS(i32 %62)
%64 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.4, i64 0, i64 0), i8* %25, i32 %63)
br label %65
65: ; preds = %53, %60, %56, %44
br label %66
66: ; preds = %32, %65, %21
%67 = add nuw i64 %22, 1
%68 = load i64, i64* %13
%69 = icmp ult i64 %67, %68
br i1 %69, label %21, label %19
70: ; preds = %1, %19
ret void
}