#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*/ cstrncpy(char *, char *, int);
char *index(char *, char);
char *strrchr(char *, char);
char *zonefile_name(char *filename, char *buf, int maxlen) {
  char *p;
  if (buf == NULL || maxlen <= 0)
    return NULL;
  buf[0] = 0;
  if (filename == NULL || !*filename)
    return buf;
  if ((p = strrchr(filename, '/')) != NULL)
    p++;
  else
    p = filename;
  cstrncpy(buf, p, maxlen);
  while ((p = index((buf), ('_'))) != NULL)
    *p = ' ';
  if (buf[0] >= 'a' && buf[0] <= 'z')
    buf[0] -= ' ';
  return buf;
}


x86 assembly (clang, -O0):
<zonefile_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1158 <zonefile_name+0x28>
cmpl   $0x0,-0x1c(%rbp)
jg     1165 <zonefile_name+0x35>
movq   $0x0,-0x8(%rbp)
jmp    1232 <zonefile_name+0x102>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     1184 <zonefile_name+0x54>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1191 <zonefile_name+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1232 <zonefile_name+0x102>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11be <zonefile_name+0x8e>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c6 <zonefile_name+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <cstrncpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x5f,%esi
call   1040 <index@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11fe <zonefile_name+0xce>
mov    -0x28(%rbp),%rax
movb   $0x20,(%rax)
jmp    11d6 <zonefile_name+0xa6>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x61,%eax
jl     122a <zonefile_name+0xfa>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7a,%eax
jg     122a <zonefile_name+0xfa>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
sub    $0x20,%ecx
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zonefile_name>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
test   %rsi,%rsi
je     11a8 <zonefile_name+0x78>
mov    %edx,%r14d
test   %edx,%edx
jle    11a8 <zonefile_name+0x78>
mov    %rsi,%rbx
mov    %rdi,%rbp
movb   $0x0,(%rsi)
test   %rdi,%rdi
je     11a5 <zonefile_name+0x75>
cmpb   $0x0,0x0(%rbp)
je     11a5 <zonefile_name+0x75>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1030 <strrchr@plt>
lea    0x1(%rax),%rsi
test   %rax,%rax
cmove  %rbp,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1050 <cstrncpy@plt>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x5f,%esi
call   1040 <index@plt>
test   %rax,%rax
je     1197 <zonefile_name+0x67>
movb   $0x20,(%rax)
jmp    1180 <zonefile_name+0x50>
mov    (%rbx),%al
lea    -0x61(%rax),%ecx
cmp    $0x19,%cl
ja     11a5 <zonefile_name+0x75>
add    $0xe0,%al
mov    %al,(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i8* @zonefile_name(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i32, i32* %7
%13 = icmp sle i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store i8* null, i8** %4
br label %67
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 0, i8* %17
%18 = load i8*, i8** %5
%19 = icmp eq i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %20, %15
%25 = load i8*, i8** %6
store i8* %25, i8** %4
br label %67
26: ; preds = %20
%27 = load i8*, i8** %5
%28 = call i8* @strrchr(i8* %27, i8 signext 47)
store i8* %28, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %8
br label %35
33: ; preds = %26
%34 = load i8*, i8** %5
store i8* %34, i8** %8
br label %35
35: ; preds = %33, %30
%36 = load i8*, i8** %6
%37 = load i8*, i8** %8
%38 = load i32, i32* %7
%39 = call i32 @cstrncpy(i8* %36, i8* %37, i32 %38)
br label %40
40: ; preds = %44, %35
%41 = load i8*, i8** %6
%42 = call i8* @index(i8* %41, i8 signext 95)
store i8* %42, i8** %8
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = load i8*, i8** %8
store i8 32, i8* %45
br label %40
46: ; preds = %40
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i64 0
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp sge i32 %50, 97
br i1 %51, label %52, label %65
52: ; preds = %46
%53 = load i8*, i8** %6
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp sle i32 %56, 122
br i1 %57, label %58, label %65
58: ; preds = %52
%59 = load i8*, i8** %6
%60 = getelementptr inbounds i8, i8* %59, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = sub nsw i32 %62, 32
%64 = trunc i32 %63 to i8
store i8 %64, i8* %60
br label %65
65: ; preds = %58, %52, %46
%66 = load i8*, i8** %6
store i8* %66, i8** %4
br label %67
67: ; preds = %65, %24, %14
%68 = load i8*, i8** %4
ret i8* %68
}

LLVM IR (-O2):
define i8* @zonefile_name(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
%5 = icmp slt i32 %2, 1
%6 = or i1 %4, %5
br i1 %6, label %30, label %7
7: ; preds = %3
store i8 0, i8* %1
%8 = icmp eq i8* %0, null
br i1 %8, label %30, label %9
9: ; preds = %7
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %9
%13 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%14 = icmp eq i8* %13, null
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = select i1 %14, i8* %0, i8* %15
%17 = tail call i32 @cstrncpy(i8* %1, i8* %16, i32 %2)
%18 = tail call i8* @index(i8* %1, i8 signext 95)
%19 = icmp eq i8* %18, null
br i1 %19, label %24, label %20
20: ; preds = %12, %20
%21 = phi i8* [ %22, %20 ], [ %18, %12 ]
store i8 32, i8* %21
%22 = tail call i8* @index(i8* %1, i8 signext 95)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %20
24: ; preds = %20, %12
%25 = load i8, i8* %1
%26 = add i8 %25, -97
%27 = icmp ult i8 %26, 26
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = add nsw i8 %25, -32
store i8 %29, i8* %1
br label %30
30: ; preds = %24, %28, %7, %9, %3
%31 = phi i8* [ null, %3 ], [ %1, %9 ], [ %1, %7 ], [ %1, %28 ], [ %1, %24 ]
ret i8* %31
}