#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(char const *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *xmalloc(size_t);
char *remove_ext(const char *str) {
  assert(str);
  size_t len;
  char *ret, *dot = NULL;
  for (len = 0; str[len]; ++len)
    if (str[len] == '.')
      dot = (char *)&str[len];
  if (dot)
    len = dot - str;
  ret = xmalloc(len + 1);
  memcpy(ret, str, len);
  ret[len] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<remove_ext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119e <remove_ext+0x6e>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1188 <remove_ext+0x58>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    118d <remove_ext+0x5d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1155 <remove_ext+0x25>
cmpq   $0x0,-0x20(%rbp)
je     11b8 <remove_ext+0x88>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1030 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_ext>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1158 <remove_ext+0x28>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rbx,%rax,1),%rcx
add    $0x1,%rax
movzbl (%rbx,%rax,1),%edx
cmp    $0x2e,%dl
je     1150 <remove_ext+0x20>
test   %dl,%dl
jne    1154 <remove_ext+0x24>
mov    %rcx,%r14
sub    %rbx,%r14
test   %rcx,%rcx
cmove  %rax,%r14
lea    0x1(%r14),%rdi
call   1030 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @remove_ext(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @assert(i8* %6)
store i8* null, i8** %5
store i64 0, i64* %3
br label %8
8: ; preds = %26, %1
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = getelementptr inbounds i8, i8* %9, i64 %10
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i64, i64* %3
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 46
br i1 %20, label %21, label %25
21: ; preds = %14
%22 = load i8*, i8** %2
%23 = load i64, i64* %3
%24 = getelementptr inbounds i8, i8* %22, i64 %23
store i8* %24, i8** %5
br label %25
25: ; preds = %21, %14
br label %26
26: ; preds = %25
%27 = load i64, i64* %3
%28 = add i64 %27, 1
store i64 %28, i64* %3
br label %8
29: ; preds = %8
%30 = load i8*, i8** %5
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i8*, i8** %5
%34 = load i8*, i8** %2
%35 = ptrtoint i8* %33 to i64
%36 = ptrtoint i8* %34 to i64
%37 = sub i64 %35, %36
store i64 %37, i64* %3
br label %38
38: ; preds = %32, %29
%39 = load i64, i64* %3
%40 = add i64 %39, 1
%41 = call i8* @xmalloc(i64 %40)
store i8* %41, i8** %4
%42 = load i8*, i8** %4
%43 = load i8*, i8** %2
%44 = load i64, i64* %3
%45 = call i32 @memcpy(i8* %42, i8* %43, i64 %44)
%46 = load i8*, i8** %4
%47 = load i64, i64* %3
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
define i8* @remove_ext(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
br label %3
3: ; preds = %9, %1
%4 = phi i64 [ 0, %1 ], [ %11, %9 ]
%5 = phi i8* [ null, %1 ], [ %10, %9 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %4
%7 = load i8, i8* %6
switch i8 %7, label %9 [
i8 0, label %12
i8 46, label %8
]
8: ; preds = %3
br label %9
9: ; preds = %3, %8
%10 = phi i8* [ %6, %8 ], [ %5, %3 ]
%11 = add i64 %4, 1
br label %3
12: ; preds = %3
%13 = icmp eq i8* %5, null
%14 = ptrtoint i8* %5 to i64
%15 = ptrtoint i8* %0 to i64
%16 = sub i64 %14, %15
%17 = select i1 %13, i64 %4, i64 %16
%18 = add i64 %17, 1
%19 = tail call i8* @xmalloc(i64 %18)
%20 = tail call i32 @memcpy(i8* %19, i8* %0, i64 %17)
%21 = getelementptr inbounds i8, i8* %19, i64 %17
store i8 0, i8* %21
ret i8* %19
}