#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 *nextCity(char *);
int pathLen(char *elem, int begin, int city_found) {
  if (city_found == 0)
    return 0;
  else {
    if (begin > 0)
      return pathLen(nextCity(elem), begin - 1, city_found);
    else
      return 128 + pathLen(nextCity(elem), begin, city_found - 1);
  }
}


x86 assembly (clang, -O0):
<pathLen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1148 <pathLen+0x28>
movl   $0x0,-0x4(%rbp)
jmp    1196 <pathLen+0x76>
cmpl   $0x0,-0x14(%rbp)
jle    1174 <pathLen+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <nextCity@plt>
mov    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x18(%rbp),%edx
call   1040 <pathLen@plt>
mov    %eax,-0x4(%rbp)
jmp    1196 <pathLen+0x76>
mov    -0x10(%rbp),%rdi
call   1030 <nextCity@plt>
mov    %rax,%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
sub    $0x1,%edx
call   1040 <pathLen@plt>
add    $0x80,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathLen>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
je     1172 <pathLen+0x62>
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%rax
mov    %edx,%r14d
shl    $0x7,%r14d
jmp    1140 <pathLen+0x30>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1030 <nextCity@plt>
mov    %r15d,%ebx
add    $0xffffffff,%ebp
je     1175 <pathLen+0x65>
mov    $0x0,%r15d
test   %ebx,%ebx
cmovs  %ebx,%r15d
jle    1130 <pathLen+0x20>
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1030 <nextCity@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
jg     1160 <pathLen+0x50>
jmp    1130 <pathLen+0x20>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @pathLen(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 0, i32* %4
br label %29
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = call i8* @nextCity(i8* %15)
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = load i32, i32* %7
%20 = call i32 @pathLen(i8* %16, i32 %18, i32 %19)
store i32 %20, i32* %4
br label %29
21: ; preds = %11
%22 = load i8*, i8** %5
%23 = call i8* @nextCity(i8* %22)
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = call i32 @pathLen(i8* %23, i32 %24, i32 %26)
%28 = add nsw i32 128, %27
store i32 %28, i32* %4
br label %29
29: ; preds = %21, %14, %10
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @pathLen(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3
%6 = shl i32 %2, 7
br label %7
7: ; preds = %5, %19
%8 = phi i32 [ %22, %19 ], [ %2, %5 ]
%9 = phi i32 [ %11, %19 ], [ %1, %5 ]
%10 = phi i8* [ %21, %19 ], [ %0, %5 ]
%11 = call i32 @llvm.smin.i32(i32 %9, i32 0)
%12 = icmp sgt i32 %9, 0
br i1 %12, label %13, label %19
13: ; preds = %7, %13
%14 = phi i8* [ %16, %13 ], [ %10, %7 ]
%15 = phi i32 [ %17, %13 ], [ %9, %7 ]
%16 = tail call i8* @nextCity(i8* %14)
%17 = add nsw i32 %15, -1
%18 = icmp sgt i32 %15, 1
br i1 %18, label %13, label %19
19: ; preds = %13, %7
%20 = phi i8* [ %10, %7 ], [ %16, %13 ]
%21 = tail call i8* @nextCity(i8* %20)
%22 = add nsw i32 %8, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %7
24: ; preds = %19, %3
%25 = phi i32 [ 0, %3 ], [ %6, %19 ]
ret i32 %25
}