#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 {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
char *GetOwner(char *, int);
int /*<<< orphan*/ Message(char *, int, char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, int, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ sscanf(char *, char *, int *);
void ListJobs(char *queueDir, int verbose) {
  struct dirent *dirp;
  DIR *dp;
  int nJobs = 0;
  if ((dp = opendir(queueDir)) == NULL) {
    char msg[240];
    sprintf(msg, "Can't read directory: %s", queueDir);
    Message("simq", 3, msg);
  }
  while ((dirp = readdir(dp)) != NULL) {
    int thisJobID;
    if (dirp->d_name[0] != '.') {
      if (sscanf(dirp->d_name, "%d", &thisJobID)) {
        if (verbose) {
          char *username;
          username = GetOwner(queueDir, thisJobID);
          printf("JobID: %d Owner: %s\n", thisJobID, username);
        }
        nJobs++;
      }
    }
  }
  closedir(dp);
  printf("Jobs waiting: %d\n", nJobs);
}


x86 assembly (clang, -O0):
<ListJobs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11df <ListJobs+0x5f>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x120(%rbp),%rdx
lea    0xe44(%rip),%rdi
mov    $0x3,%esi
call   1050 <Message@plt>
jmp    11e4 <ListJobs+0x64>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1280 <ListJobs+0x100>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     127b <ListJobs+0xfb>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe02(%rip),%rsi
lea    -0x124(%rbp),%rdx
call   1090 <sscanf@plt>
cmp    $0x0,%rax
je     1276 <ListJobs+0xf6>
cmpl   $0x0,-0xc(%rbp)
je     126d <ListJobs+0xed>
mov    -0x8(%rbp),%rdi
mov    -0x124(%rbp),%esi
call   1080 <GetOwner@plt>
mov    %rax,-0x130(%rbp)
mov    -0x124(%rbp),%esi
mov    -0x130(%rbp),%rdx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127b <ListJobs+0xfb>
jmp    11e4 <ListJobs+0x64>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x24(%rbp),%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ListJobs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %esi,%r15d
mov    %rdi,%r14
call   1030 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11cd <ListJobs+0x4d>
lea    0xe55(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14,%rdx
call   10a0 <sprintf@plt>
lea    0xe59(%rip),%rdi
mov    $0x3,%esi
mov    %rbp,%rdx
call   1050 <Message@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     123e <ListJobs+0xbe>
lea    0xe3d(%rip),%r12
mov    %rsp,%r13
xor    %ebp,%ebp
jmp    1200 <ListJobs+0x80>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1240 <ListJobs+0xc0>
mov    (%rax),%rdi
cmpb   $0x2e,(%rdi)
je     11f3 <ListJobs+0x73>
mov    %r12,%rsi
mov    %r13,%rdx
call   1090 <sscanf@plt>
test   %rax,%rax
je     11f3 <ListJobs+0x73>
test   %r15d,%r15d
je     11f0 <ListJobs+0x70>
mov    (%rsp),%esi
mov    %r14,%rdi
call   1080 <GetOwner@plt>
mov    (%rsp),%esi
lea    0xdef(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f0 <ListJobs+0x70>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1060 <closedir@plt>
lea    0xde7(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [25 x i8] c"Can't read directory: %s\00"
@.str.1 = [5 x i8] c"simq\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [21 x i8] c"JobID: %d Owner: %s\0A\00"
@.str.4 = [18 x i8] c"Jobs waiting: %d\0A\00"
define void @ListJobs(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [240 x i8]
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %7
%11 = load i8*, i8** %3
%12 = call i32* @opendir(i8* %11)
store i32* %12, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [240 x i8], [240 x i8]* %8, i64 0, i64 0
%19 = call i32 @Message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %18)
br label %20
20: ; preds = %14, %2
br label %21
21: ; preds = %53, %20
%22 = load i32*, i32** %6
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %5
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %54
25: ; preds = %21
%26 = load %struct.dirent*, %struct.dirent** %5
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 46
br i1 %32, label %33, label %53
33: ; preds = %25
%34 = load %struct.dirent*, %struct.dirent** %5
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i64 @sscanf(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %33
%40 = load i32, i32* %4
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = load i8*, i8** %3
%44 = load i32, i32* %9
%45 = call i8* @GetOwner(i8* %43, i32 %44)
store i8* %45, i8** %10
%46 = load i32, i32* %9
%47 = load i8*, i8** %10
%48 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %46, i8* %47)
br label %49
49: ; preds = %42, %39
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %52
52: ; preds = %49, %33
br label %53
53: ; preds = %52, %25
br label %21
54: ; preds = %21
%55 = load i32*, i32** %6
%56 = call i32 @closedir(i32* %55)
%57 = load i32, i32* %7
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %57)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [25 x i8] c"Can't read directory: %s\00"
@.str.1 = [5 x i8] c"simq\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [21 x i8] c"JobID: %d Owner: %s\0A\00"
@.str.4 = [18 x i8] c"Jobs waiting: %d\0A\00"
define void @ListJobs(i8* %0, i32 %1) {
%3 = alloca [240 x i8]
%4 = alloca i32
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds [240 x i8], [240 x i8]* %3, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @Message(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 3, i8* %8)
br label %11
11: ; preds = %7, %2
%12 = call %struct.dirent* @readdir(i32* %5)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %39, label %14
14: ; preds = %11
%15 = bitcast i32* %4 to i8*
%16 = icmp eq i32 %1, 0
br label %17
17: ; preds = %14, %35
%18 = phi %struct.dirent* [ %12, %14 ], [ %37, %35 ]
%19 = phi i32 [ 0, %14 ], [ %36, %35 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 46
br i1 %23, label %35, label %24
24: ; preds = %17
%25 = call i64 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %35, label %27
27: ; preds = %24
br i1 %16, label %33, label %28
28: ; preds = %27
%29 = load i32, i32* %4
%30 = call i8* @GetOwner(i8* %0, i32 %29)
%31 = load i32, i32* %4
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %31, i8* %30)
br label %33
33: ; preds = %28, %27
%34 = add nsw i32 %19, 1
br label %35
35: ; preds = %24, %33, %17
%36 = phi i32 [ %34, %33 ], [ %19, %24 ], [ %19, %17 ]
%37 = call %struct.dirent* @readdir(i32* %5)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %39, label %17
39: ; preds = %35, %11
%40 = phi i32 [ 0, %11 ], [ %36, %35 ]
%41 = call i32 @closedir(i32* %5)
%42 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %40)
ret void
}