#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 *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
char *remove_extension(char *mapname) {
  char *ptr, *ptr2;
  ptr = strchr(mapname, '.');
  if (ptr) {
    while (ptr[1] && (ptr2 = strchr(ptr + 1, '.')))
      ptr = ptr2;
    if (strcmp(ptr, ".gat") == 0)
      *ptr = '\0';
  }
  return mapname;
}


x86 assembly (clang, -O0):
<remove_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c7 <remove_extension+0xa7>
jmp    114e <remove_extension+0x2e>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1184 <remove_extension+0x64>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1194 <remove_extension+0x74>
jmp    11a1 <remove_extension+0x81>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    114e <remove_extension+0x2e>
mov    -0x10(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c2 <remove_extension+0xa2>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c7 <remove_extension+0xa7>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_extension>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1173 <remove_extension+0x53>
cs nopw 0x0(%rax,%rax,1)
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
je     115c <remove_extension+0x3c>
lea    0x1(%rbx),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1140 <remove_extension+0x20>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1173 <remove_extension+0x53>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c".gat\00"
define i8* @remove_extension(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strchr(i8* %5, i8 signext 46)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %32
9: ; preds = %1
br label %10
10: ; preds = %23, %9
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %10
%17 = load i8*, i8** %3
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = call i8* @strchr(i8* %18, i8 signext 46)
store i8* %19, i8** %4
%20 = icmp ne i8* %19, null
br label %21
21: ; preds = %16, %10
%22 = phi i1 [ false, %10 ], [ %20, %16 ]
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = load i8*, i8** %4
store i8* %24, i8** %3
br label %10
25: ; preds = %21
%26 = load i8*, i8** %3
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i8*, i8** %3
store i8 0, i8* %30
br label %31
31: ; preds = %29, %25
br label %32
32: ; preds = %31, %1
%33 = load i8*, i8** %2
ret i8* %33
}

LLVM IR (-O2):
@.str = [5 x i8] c".gat\00"
define i8* @remove_extension(i8* returned %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%3 = icmp eq i8* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1, %9
%5 = phi i8* [ %10, %9 ], [ %2, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = tail call i8* @strchr(i8* %6, i8 signext 46)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %4
12: ; preds = %4, %9
%13 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i8 0, i8* %5
br label %16
16: ; preds = %12, %15, %1
ret i8* %0
}