#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 */

/* Type definitions */
struct dirent {
  int dummy;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ execl(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait();
int main(int argc, char **argv) {
  DIR *dir;
  struct dirent *dirent;
  int i;
  if (argc != 4) {
    fputs("usage: noqueue sleep nosend spool\n", stderr);
    exit(1);
  }
  while (1) {
    if (!(dir = opendir(argv[3]))) {
      perror("Can't open directory");
      exit(1);
    }
    for (i = 0; (dirent = readdir(dir)) != NULL; i++)
      ;
    closedir(dir);
    if (i != 2) {
      if (fork()) {
        wait();
      } else {
        execl(argv[2], NULL);
        perror("Can't exec nosend process");
        _exit(1);
      }
    }
    sleep(atoi(argv[1]));
  }
}


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)
cmpl   $0x4,-0x8(%rbp)
je     11ff <main+0x3f>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    0xe10(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1204 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1235 <main+0x75>
lea    0xdfd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1266 <main+0xa6>
jmp    1258 <main+0x98>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123c <main+0x7c>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
cmpl   $0x2,-0x24(%rbp)
je     12c2 <main+0x102>
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%rax
je     1296 <main+0xd6>
mov    $0x0,%al
call   10d0 <wait@plt>
jmp    12bd <main+0xfd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   10b0 <execl@plt>
lea    0xd8a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    12c2 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   10c0 <sleep@plt>
jmp    1204 <main+0x44>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x4,%edi
jne    11f0 <main+0x30>
mov    %rsi,%r14
mov    0x18(%rsi),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
jne    120f <main+0x4f>
lea    0xe42(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    0xe00(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
jmp    1241 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   10c0 <sleep@plt>
mov    0x18(%r14),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11da <main+0x1a>
mov    $0x3,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readdir@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1250 <main+0x90>
mov    %rbx,%rdi
call   1060 <closedir@plt>
test   %ebp,%ebp
je     1220 <main+0x60>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %rax,%rax
je     1281 <main+0xc1>
xor    %eax,%eax
call   10d0 <wait@plt>
jmp    1220 <main+0x60>
mov    0x10(%r14),%rdi
xor    %esi,%esi
call   10b0 <execl@plt>
lea    0xda5(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [35 x i8] c"usage: noqueue sleep nosend spool\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open directory\00"
@.str.2 = [26 x i8] c"Can't exec nosend process\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
br label %16
16: ; preds = %15, %52
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = call i32* @opendir(i8* %19)
store i32* %20, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
store i32 0, i32* %8
br label %26
26: ; preds = %31, %25
%27 = load i32*, i32** %6
%28 = call %struct.dirent* @readdir(i32* %27)
store %struct.dirent* %28, %struct.dirent** %7
%29 = icmp ne %struct.dirent* %28, null
br i1 %29, label %30, label %34
30: ; preds = %26
br label %31
31: ; preds = %30
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %26
34: ; preds = %26
%35 = load i32*, i32** %6
%36 = call i32 @closedir(i32* %35)
%37 = load i32, i32* %8
%38 = icmp ne i32 %37, 2
br i1 %38, label %39, label %52
39: ; preds = %34
%40 = call i64 (...) @fork()
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (...) @wait()
br label %51
44: ; preds = %39
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = call i32 @execl(i8* %47, i32* null)
%49 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @_exit(i32 1)
unreachable
51: ; preds = %42
br label %52
52: ; preds = %51, %34
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
%57 = call i32 @sleep(i32 %56)
br label %16
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [35 x i8] c"usage: noqueue sleep nosend spool\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open directory\00"
@.str.2 = [26 x i8] c"Can't exec nosend process\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 3
%6 = load i8*, i8** %5
%7 = tail call i32* @opendir(i8* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 1
br label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9, %39
%16 = phi i32* [ %7, %9 ], [ %44, %39 ]
br label %20
17: ; preds = %39, %4
%18 = tail call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %20, %15
%21 = phi i32 [ %24, %20 ], [ 0, %15 ]
%22 = tail call %struct.dirent* @readdir(i32* %16)
%23 = icmp eq %struct.dirent* %22, null
%24 = add nuw nsw i32 %21, 1
br i1 %23, label %25, label %20
25: ; preds = %20
%26 = tail call i32 @closedir(i32* %16)
%27 = icmp eq i32 %21, 2
br i1 %27, label %39, label %28
28: ; preds = %25
%29 = tail call i64 (...) @fork()
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = tail call i32 (...) @wait()
br label %39
33: ; preds = %28
%34 = getelementptr inbounds i8*, i8** %1, i64 2
%35 = load i8*, i8** %34
%36 = tail call i32 @execl(i8* %35, i32* null)
%37 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%38 = tail call i32 @_exit(i32 1)
unreachable
39: ; preds = %31, %25
%40 = load i8*, i8** %10
%41 = tail call i32 @atoi(i8* %40)
%42 = tail call i32 @sleep(i32 %41)
%43 = load i8*, i8** %5
%44 = tail call i32* @opendir(i8* %43)
%45 = icmp eq i32* %44, null
br i1 %45, label %17, label %15
}