#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 *copy_string(char *);
char *strchr(char *, char);
char *basecfg(char *cfgfile) {
  char *c = cfgfile;
  char *next;
  while ((next = strchr(c, '/'))) {
    c = next + 1;
  }
  c = copy_string(c);
  next = strchr(c, '.');
  if (next)
    *next = 0;
  return c;
}


x86 assembly (clang, -O0):
<basecfg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1161 <basecfg+0x41>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <basecfg+0x14>
mov    -0x10(%rbp),%rdi
call   1030 <copy_string@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1192 <basecfg+0x72>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basecfg>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
jne    1130 <basecfg+0x10>
mov    %rbx,%rdi
call   1030 <copy_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1166 <basecfg+0x46>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i8* @basecfg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %10, %1
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %12, i8** %3
br label %6
13: ; preds = %6
%14 = load i8*, i8** %3
%15 = call i8* @copy_string(i8* %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i8* @strchr(i8* %16, i8 signext 46)
store i8* %17, i8** %4
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %13
%21 = load i8*, i8** %4
store i8 0, i8* %21
br label %22
22: ; preds = %20, %13
%23 = load i8*, i8** %3
ret i8* %23
}

LLVM IR (-O2):
define i8* @basecfg(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 47)
%5 = icmp eq i8* %4, null
%6 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = tail call i8* @copy_string(i8* %3)
%9 = tail call i8* @strchr(i8* dereferenceable(1) %8, i8 signext 46)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %7
store i8 0, i8* %9
br label %12
12: ; preds = %11, %7
ret i8* %8
}