#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 */
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
unsigned int strlen(char const *);
int base_name(const char *dir, char **out) {
  static char path_buf[1024];
  const char *s;
  const char *t;
  const char *u;
  unsigned int len;
  unsigned int nlen;
  len = strlen(dir);
  if (!len) {
    path_buf[0] = '.';
    path_buf[1] = 0;
    *out = path_buf;
    return 1;
  }
  if (len >= 1024)
    return 0;
  s = dir;
  t = s + (len - 1);
  while ((t > s) && (t[0] == '/'))
    --t;
  if ((t == s) && (t[0] == '/')) {
    path_buf[0] = '/';
    path_buf[1] = 0;
    *out = path_buf;
    return 1;
  }
  u = t;
  while ((u > s) && (*(u - 1) != '/'))
    --u;
  nlen = (t - u) + 1;
  memcpy(path_buf, u, nlen);
  path_buf[nlen] = 0;
  *out = path_buf;
  return 1;
}


x86 assembly (clang, -O0):
<base_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    116e <base_name+0x4e>
movb   $0x2e,0x2ef3(%rip)
movb   $0x0,0x2eed(%rip)
mov    -0x18(%rbp),%rax
lea    0x2ee1(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12c3 <base_name+0x1a3>
cmpl   $0x400,-0x34(%rbp)
jb     1187 <base_name+0x67>
movl   $0x0,-0x4(%rbp)
jmp    12c3 <base_name+0x1a3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x39(%rbp)
jbe    11c5 <base_name+0xa5>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11d5 <base_name+0xb5>
jmp    11e6 <base_name+0xc6>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    11a2 <base_name+0x82>
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    122c <base_name+0x10c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    122c <base_name+0x10c>
movb   $0x2f,0x2e35(%rip)
movb   $0x0,0x2e2f(%rip)
mov    -0x18(%rbp),%rax
lea    0x2e23(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12c3 <base_name+0x1a3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x3a(%rbp)
jbe    1258 <base_name+0x138>
mov    -0x30(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    1268 <base_name+0x148>
jmp    1279 <base_name+0x159>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
jmp    1234 <base_name+0x114>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
lea    0x2da7(%rip),%rdi
call   1040 <memcpy@plt>
mov    -0x38(%rbp),%eax
mov    %eax,%ecx
lea    0x2d96(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
lea    0x2d87(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base_name>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
je     1172 <base_name+0x52>
xor    %ecx,%ecx
cmp    $0x3ff,%eax
ja     11cf <base_name+0xaf>
add    $0xffffffff,%eax
lea    (%r15,%rax,1),%rcx
test   %eax,%eax
je     115e <base_name+0x3e>
nopl   0x0(%rax)
cmpb   $0x2f,(%rcx)
jne    115e <base_name+0x3e>
add    $0xffffffffffffffff,%rcx
cmp    %r15,%rcx
ja     1150 <base_name+0x30>
cmp    %r15,%rcx
jne    1182 <base_name+0x62>
cmpb   $0x2f,(%r15)
jne    1182 <base_name+0x62>
movb   $0x2f,0x2ed0(%rip)
jmp    1179 <base_name+0x59>
movb   $0x2e,0x2ec7(%rip)
lea    0x2ec1(%rip),%rax
jmp    11bd <base_name+0x9d>
mov    $0x1,%eax
nopw   0x0(%rax,%rax,1)
mov    %rcx,%rsi
mov    %eax,%ebx
cmp    %r15,%rcx
jbe    11a7 <base_name+0x87>
lea    -0x1(%rsi),%rcx
lea    0x1(%rbx),%eax
cmpb   $0x2f,-0x1(%rsi)
jne    1190 <base_name+0x70>
lea    0x2e92(%rip),%r15
mov    %r15,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %ebx,%eax
add    %r15,%rax
movb   $0x0,(%rax)
lea    0x2e79(%rip),%rax
mov    %rax,(%r14)
mov    $0x1,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@base_name.path_buf = internal global [1024 x i8] zeroinitializer
define i32 @base_name(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %2
store i8 46, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 1)
%16 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8** %16
store i32 1, i32* %3
br label %87
17: ; preds = %2
%18 = load i32, i32* %9
%19 = icmp uge i32 %18, 1024
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 0, i32* %3
br label %87
21: ; preds = %17
%22 = load i8*, i8** %4
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = load i32, i32* %9
%25 = sub i32 %24, 1
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
store i8* %27, i8** %7
br label %28
28: ; preds = %40, %21
%29 = load i8*, i8** %7
%30 = load i8*, i8** %6
%31 = icmp ugt i8* %29, %30
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 47
br label %38
38: ; preds = %32, %28
%39 = phi i1 [ false, %28 ], [ %37, %32 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 -1
store i8* %42, i8** %7
br label %28
43: ; preds = %38
%44 = load i8*, i8** %7
%45 = load i8*, i8** %6
%46 = icmp eq i8* %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 47
br i1 %52, label %53, label %55
53: ; preds = %47
store i8 47, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 1)
%54 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8** %54
store i32 1, i32* %3
br label %87
55: ; preds = %47, %43
%56 = load i8*, i8** %7
store i8* %56, i8** %8
br label %57
57: ; preds = %69, %55
%58 = load i8*, i8** %8
%59 = load i8*, i8** %6
%60 = icmp ugt i8* %58, %59
br i1 %60, label %61, label %67
61: ; preds = %57
%62 = load i8*, i8** %8
%63 = getelementptr inbounds i8, i8* %62, i64 -1
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 47
br label %67
67: ; preds = %61, %57
%68 = phi i1 [ false, %57 ], [ %66, %61 ]
br i1 %68, label %69, label %72
69: ; preds = %67
%70 = load i8*, i8** %8
%71 = getelementptr inbounds i8, i8* %70, i32 -1
store i8* %71, i8** %8
br label %57
72: ; preds = %67
%73 = load i8*, i8** %7
%74 = load i8*, i8** %8
%75 = ptrtoint i8* %73 to i64
%76 = ptrtoint i8* %74 to i64
%77 = sub i64 %75, %76
%78 = add nsw i64 %77, 1
%79 = trunc i64 %78 to i32
store i32 %79, i32* %10
%80 = load i8*, i8** %8
%81 = load i32, i32* %10
%82 = call i32 @memcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8* %80, i32 %81)
%83 = load i32, i32* %10
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 %84
store i8 0, i8* %85
%86 = load i8**, i8*** %5
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8** %86
store i32 1, i32* %3
br label %87
87: ; preds = %72, %53, %20, %15
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@base_name.path_buf = internal global [1024 x i8] zeroinitializer
define i32 @base_name(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %2
store i8 46, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0)
br label %44
6: ; preds = %2
%7 = icmp ugt i32 %3, 1023
br i1 %7, label %46, label %8
8: ; preds = %6
%9 = add nsw i32 %3, -1
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = icmp eq i32 %9, 0
br i1 %12, label %20, label %13
13: ; preds = %8, %17
%14 = phi i8* [ %18, %17 ], [ %11, %8 ]
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 47
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = getelementptr inbounds i8, i8* %14, i64 -1
%19 = icmp ugt i8* %18, %0
br i1 %19, label %13, label %20
20: ; preds = %13, %17, %8
%21 = phi i8* [ %11, %8 ], [ %18, %17 ], [ %14, %13 ]
%22 = icmp eq i8* %21, %0
br i1 %22, label %24, label %23
23: ; preds = %24, %20
br label %28
24: ; preds = %20
%25 = load i8, i8* %0
%26 = icmp eq i8 %25, 47
br i1 %26, label %27, label %23
27: ; preds = %24
store i8 47, i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0)
br label %44
28: ; preds = %23, %31
%29 = phi i8* [ %32, %31 ], [ %21, %23 ]
%30 = icmp ugt i8* %29, %0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = getelementptr inbounds i8, i8* %29, i64 -1
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 47
br i1 %34, label %35, label %28
35: ; preds = %28, %31
%36 = ptrtoint i8* %21 to i64
%37 = ptrtoint i8* %29 to i64
%38 = sub i64 %36, %37
%39 = trunc i64 %38 to i32
%40 = add i32 %39, 1
%41 = tail call i32 @memcpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8* %29, i32 %40)
%42 = zext i32 %40 to i64
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 %42
br label %44
44: ; preds = %5, %27, %35
%45 = phi i8* [ %43, %35 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 1), %27 ], [ getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 1), %5 ]
store i8 0, i8* %45
store i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @base_name.path_buf, i64 0, i64 0), i8** %1
br label %46
46: ; preds = %44, %6
%47 = phi i32 [ 0, %6 ], [ 1, %44 ]
ret i32 %47
}