#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 *basename(char const *);
void filename2modname(char *modname, const char *filename) {
  const char *afterslash;
  unsigned int i;
  afterslash = basename(filename);
  for (i = 0; afterslash[i] && afterslash[i] != '.'; i++) {
    if (afterslash[i] == '-')
      modname[i] = '_';
    else
      modname[i] = afterslash[i];
  }
  modname[i] = '\0';
}


x86 assembly (clang, -O0):
<filename2modname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <basename@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1161 <filename2modname+0x51>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1171 <filename2modname+0x61>
jmp    11bc <filename2modname+0xac>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    1195 <filename2modname+0x85>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x5f,(%rax,%rcx,1)
jmp    11a9 <filename2modname+0x99>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
jmp    11ae <filename2modname+0x9e>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1134 <filename2modname+0x24>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filename2modname>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <basename@plt>
xor    %ecx,%ecx
jmp    1137 <filename2modname+0x27>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %bl,(%r14,%rcx,1)
add    $0x1,%ecx
mov    %ecx,%ecx
movzbl (%rax,%rcx,1),%edx
mov    $0x5f,%bl
cmp    $0x2d,%dl
je     1130 <filename2modname+0x20>
test   %dl,%dl
je     1151 <filename2modname+0x41>
cmp    $0x2e,%dl
je     1151 <filename2modname+0x41>
mov    %edx,%ebx
jmp    1130 <filename2modname+0x20>
movb   $0x0,(%r14,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @filename2modname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i8* @basename(i8* %7)
store i8* %8, i8** %5
store i32 0, i32* %6
br label %9
9: ; preds = %51, %2
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %9
%18 = load i8*, i8** %5
%19 = load i32, i32* %6
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 46
br label %25
25: ; preds = %17, %9
%26 = phi i1 [ false, %9 ], [ %24, %17 ]
br i1 %26, label %27, label %54
27: ; preds = %25
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 45
br i1 %34, label %35, label %40
35: ; preds = %27
%36 = load i8*, i8** %3
%37 = load i32, i32* %6
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 95, i8* %39
br label %50
40: ; preds = %27
%41 = load i8*, i8** %5
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = load i8*, i8** %3
%47 = load i32, i32* %6
%48 = zext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
br label %50
50: ; preds = %40, %35
br label %51
51: ; preds = %50
%52 = load i32, i32* %6
%53 = add i32 %52, 1
store i32 %53, i32* %6
br label %9
54: ; preds = %25
%55 = load i8*, i8** %3
%56 = load i32, i32* %6
%57 = zext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
ret void
}

LLVM IR (-O2):
define void @filename2modname(i8* nocapture writeonly %0, i8* %1) {
%3 = tail call i8* @basename(i8* %1)
br label %4
4: ; preds = %10, %2
%5 = phi i32 [ 0, %2 ], [ %13, %10 ]
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %3, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 0, label %14
i8 46, label %14
i8 45, label %10
]
9: ; preds = %4
br label %10
10: ; preds = %4, %9
%11 = phi i8 [ %8, %9 ], [ 95, %4 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %6
store i8 %11, i8* %12
%13 = add i32 %5, 1
br label %4
14: ; preds = %4, %4
%15 = zext i32 %5 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %16
ret void
}