#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*/ assert(int);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
size_t strcspn(char const *, char *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *build_filename(const char *string, const char *ext) {
  char *filename = 0;
  size_t len;
  len = strcspn(string, ".");
  assert(len != 0);
  filename = (char *)malloc(len + strlen(ext) + 1);
  assert(filename != 0);
  strncpy(filename, string, len);
  filename[len] = '\0';
  strcat(filename, ext);
  return filename;
}


x86 assembly (clang, -O0):
<build_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_filename>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8b(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%r12
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%r12,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i8* @build_filename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = call i64 @strcspn(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i64 %8, i64* %6
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i64, i64* %6
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
%16 = add i64 %13, %15
%17 = add i64 %16, 1
%18 = call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %5
%25 = load i8*, i8** %3
%26 = load i64, i64* %6
%27 = call i32 @strncpy(i8* %24, i8* %25, i64 %26)
%28 = load i8*, i8** %5
%29 = load i64, i64* %6
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %5
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i8* @build_filename(i8* %0, i8* %1) {
%3 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i64 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add i64 %3, 1
%9 = add i64 %8, %7
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp ne i64 %10, 0
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @strncpy(i8* %11, i8* %0, i64 %3)
%16 = getelementptr inbounds i8, i8* %11, i64 %3
store i8 0, i8* %16
%17 = tail call i32 @strcat(i8* %11, i8* %1)
ret i8* %11
}