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

/* Variables and functions */
char **dir_list(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ paths_free(char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int test_2files_dir(void) {
  int ret, one, two;
  char **paths, **cur;
  paths = dir_list("data/2files_dir", NULL);
  one = two = ret = 0;
  if (!paths) {
    fprintf(stderr, "ERROR: list is NULL\n");
    return 1;
  }
  cur = paths;
  while (*cur) {
    if (!strcmp(*cur, "data/2files_dir/one")) {
      one++;
    } else if (!strcmp(*cur, "data/2files_dir/two")) {
      two++;
    } else {
      fprintf(stderr, "ERROR: wrong item: %s\n", *cur);
      ret = 1;
    }
    cur++;
  }
  if (!ret && one == 1 && two == 1)
    ret = 0;
  else
    ret = 1;
  paths_free(paths);
  return ret;
}


x86 assembly (clang, -O0):
<test_2files_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <dir_list@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119f <test_2files_dir+0x5f>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <test_2files_dir+0x144>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1244 <test_2files_dir+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe62(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11df <test_2files_dir+0x9f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1233 <test_2files_dir+0xf3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1209 <test_2files_dir+0xc9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122e <test_2files_dir+0xee>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1233 <test_2files_dir+0xf3>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    11a7 <test_2files_dir+0x67>
cmpl   $0x0,-0x8(%rbp)
jne    126e <test_2files_dir+0x12e>
cmpl   $0x1,-0xc(%rbp)
jne    126e <test_2files_dir+0x12e>
cmpl   $0x1,-0x10(%rbp)
jne    126e <test_2files_dir+0x12e>
movl   $0x0,-0x8(%rbp)
jmp    1275 <test_2files_dir+0x135>
movl   $0x1,-0x8(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <paths_free@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_2files_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
call   1060 <dir_list@plt>
test   %rax,%rax
je     1222 <test_2files_dir+0xe2>
mov    %rax,(%rsp)
mov    (%rax),%rbx
mov    $0x0,%r14d
mov    $0x0,%ebp
test   %rbx,%rbx
je     1205 <test_2files_dir+0xc5>
mov    (%rsp),%r15
add    $0x8,%r15
lea    0xe96(%rip),%r13
xor    %ebp,%ebp
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11b0 <test_2files_dir+0x70>
nopl   0x0(%rax)
add    $0x1,%r14d
mov    (%r15),%rbx
add    $0x8,%r15
test   %rbx,%rbx
je     1205 <test_2files_dir+0xc5>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11a0 <test_2files_dir+0x60>
mov    %rbx,%rdi
lea    0xe70(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1200 <test_2files_dir+0xc0>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r12d
jmp    11a4 <test_2files_dir+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
jmp    11a4 <test_2files_dir+0x64>
xor    $0x1,%r14d
or     %r12d,%r14d
xor    $0x1,%ebp
xor    %ebx,%ebx
or     %r14d,%ebp
setne  %bl
mov    (%rsp),%rdi
call   1030 <paths_free@plt>
jmp    123e <test_2files_dir+0xfe>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"data/2files_dir\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR: list is NULL\0A\00"
@.str.2 = [20 x i8] c"data/2files_dir/one\00"
@.str.3 = [20 x i8] c"data/2files_dir/two\00"
@.str.4 = [23 x i8] c"ERROR: wrong item: %s\0A\00"
define i32 @test_2files_dir() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = call i8** @dir_list(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null)
store i8** %7, i8*** %5
store i32 0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %3
%8 = load i8**, i8*** %5
%9 = icmp ne i8** %8, null
br i1 %9, label %13, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %59
13: ; preds = %0
%14 = load i8**, i8*** %5
store i8** %14, i8*** %6
br label %15
15: ; preds = %41, %13
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %44
19: ; preds = %15
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %41
27: ; preds = %19
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %40
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8**, i8*** %6
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %38)
store i32 1, i32* %2
br label %40
40: ; preds = %35, %32
br label %41
41: ; preds = %40, %24
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i32 1
store i8** %43, i8*** %6
br label %15
44: ; preds = %15
%45 = load i32, i32* %2
%46 = icmp ne i32 %45, 0
br i1 %46, label %54, label %47
47: ; preds = %44
%48 = load i32, i32* %3
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load i32, i32* %4
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %54
53: ; preds = %50
store i32 0, i32* %2
br label %55
54: ; preds = %50, %47, %44
store i32 1, i32* %2
br label %55
55: ; preds = %54, %53
%56 = load i8**, i8*** %5
%57 = call i32 @paths_free(i8** %56)
%58 = load i32, i32* %2
store i32 %58, i32* %1
br label %59
59: ; preds = %55, %10
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [16 x i8] c"data/2files_dir\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"ERROR: list is NULL\0A\00"
@.str.2 = [20 x i8] c"data/2files_dir/one\00"
@.str.3 = [20 x i8] c"data/2files_dir/two\00"
@.str.4 = [23 x i8] c"ERROR: wrong item: %s\0A\00"
define i32 @test_2files_dir() {
%1 = tail call i8** @dir_list(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null)
%2 = icmp eq i8** %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %34, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %45
9: ; preds = %3, %27
%10 = phi i8* [ %32, %27 ], [ %4, %3 ]
%11 = phi i8** [ %31, %27 ], [ %1, %3 ]
%12 = phi i32 [ %30, %27 ], [ 0, %3 ]
%13 = phi i32 [ %29, %27 ], [ 0, %3 ]
%14 = phi i32 [ %28, %27 ], [ 0, %3 ]
%15 = tail call i32 @strcmp(i8* %10, i8* dereferenceable(20) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = add nsw i32 %13, 1
br label %27
19: ; preds = %9
%20 = tail call i32 @strcmp(i8* %10, i8* dereferenceable(20) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = add nsw i32 %12, 1
br label %27
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %27
27: ; preds = %22, %24, %17
%28 = phi i32 [ 1, %24 ], [ %14, %22 ], [ %14, %17 ]
%29 = phi i32 [ %13, %24 ], [ %13, %22 ], [ %18, %17 ]
%30 = phi i32 [ %12, %24 ], [ %23, %22 ], [ %12, %17 ]
%31 = getelementptr inbounds i8*, i8** %11, i64 1
%32 = load i8*, i8** %31
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %9
34: ; preds = %27, %3
%35 = phi i32 [ 0, %3 ], [ %28, %27 ]
%36 = phi i32 [ 0, %3 ], [ %29, %27 ]
%37 = phi i32 [ 0, %3 ], [ %30, %27 ]
%38 = icmp ne i32 %35, 0
%39 = icmp ne i32 %36, 1
%40 = select i1 %38, i1 true, i1 %39
%41 = icmp ne i32 %37, 1
%42 = select i1 %40, i1 true, i1 %41
%43 = zext i1 %42 to i32
%44 = tail call i32 @paths_free(i8** %1)
br label %45
45: ; preds = %34, %6
%46 = phi i32 [ %43, %34 ], [ 1, %6 ]
ret i32 %46
}