#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 */
typedef int /*<<< orphan*/ name;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int _search(char **, int, char *);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int);
int pathwalk(char **searchpath, int length, int files, int target) {
  char name[PATH_MAX + 1];
  int i, found;
  int count = 0;
  for (i = 0; i < files; i++) {
    snprintf(name, sizeof(name), "%d.%d", target, i);
    found = _search(searchpath, length, name);
    assert(found == target);
    if (found != -1)
      count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<pathwalk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fb <pathwalk+0xcb>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x40(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <_search@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0xffffffff,-0x30(%rbp)
je     11e8 <pathwalk+0xb8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ed <pathwalk+0xbd>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1186 <pathwalk+0x56>
mov    -0x34(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathwalk>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,-0x50(%rbp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%ebx
add    $0x1,%ebx
mov    %rsp,%rdi
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
test   %edx,%edx
jle    11e7 <pathwalk+0xb7>
mov    %esi,%r13d
xor    %r12d,%r12d
mov    %rdi,-0x48(%rbp)
xor    %r14d,%r14d
mov    %ecx,-0x2c(%rbp)
mov    %edx,-0x34(%rbp)
mov    %esi,-0x30(%rbp)
mov    %rbx,-0x40(%rbp)
mov    -0x48(%rbp),%rbx
mov    -0x2c(%rbp),%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    -0x40(%rbp),%rsi
lea    0xe62(%rip),%rdx
mov    %r15d,%ecx
mov    %r14d,%r8d
call   1030 <snprintf@plt>
mov    -0x50(%rbp),%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1040 <_search@plt>
mov    %eax,%r13d
xor    %edi,%edi
cmp    %r15d,%eax
sete   %dil
call   1050 <assert@plt>
mov    -0x34(%rbp),%edx
xor    %eax,%eax
cmp    $0xffffffff,%r13d
mov    -0x30(%rbp),%r13d
setne  %al
add    %eax,%r12d
add    $0x1,%r14d
cmp    %r14d,%edx
jne    1190 <pathwalk+0x60>
jmp    11ea <pathwalk+0xba>
xor    %r12d,%r12d
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%d.%d\00"
define i32 @pathwalk(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8** %0, i8*** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* @PATH_MAX
%15 = add nsw i32 %14, 1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i8, i64 %16
store i64 %16, i64* %10
store i32 0, i32* %13
store i32 0, i32* %11
br label %19
19: ; preds = %42, %4
%20 = load i32, i32* %11
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %45
23: ; preds = %19
%24 = trunc i64 %16 to i32
%25 = load i32, i32* %8
%26 = load i32, i32* %11
%27 = call i32 @snprintf(i8* %18, i32 %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
%28 = load i8**, i8*** %5
%29 = load i32, i32* %6
%30 = call i32 @_search(i8** %28, i32 %29, i8* %18)
store i32 %30, i32* %12
%31 = load i32, i32* %12
%32 = load i32, i32* %8
%33 = icmp eq i32 %31, %32
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %12
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %23
%39 = load i32, i32* %13
%40 = add nsw i32 %39, 1
store i32 %40, i32* %13
br label %41
41: ; preds = %38, %23
br label %42
42: ; preds = %41
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
store i32 %44, i32* %11
br label %19
45: ; preds = %19
%46 = load i32, i32* %13
%47 = load i8*, i8** %9
ret i32 %46
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%d.%d\00"
define i32 @pathwalk(i8** %0, i32 %1, i32 %2, i32 %3) {
%5 = load i32, i32* @PATH_MAX
%6 = add nsw i32 %5, 1
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp sgt i32 %2, 0
br i1 %9, label %10, label %23
10: ; preds = %4, %10
%11 = phi i32 [ %20, %10 ], [ 0, %4 ]
%12 = phi i32 [ %21, %10 ], [ 0, %4 ]
%13 = call i32 @snprintf(i8* %8, i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %12)
%14 = call i32 @_search(i8** %0, i32 %1, i8* %8)
%15 = icmp eq i32 %14, %3
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = icmp ne i32 %14, -1
%19 = zext i1 %18 to i32
%20 = add nuw nsw i32 %11, %19
%21 = add nuw nsw i32 %12, 1
%22 = icmp eq i32 %21, %2
br i1 %22, label %23, label %10
23: ; preds = %10, %4
%24 = phi i32 [ 0, %4 ], [ %20, %10 ]
ret i32 %24
}