#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strrchr(char *, char);
char *strextension(char *strin, char *extension) {
  char *strtemp, *tp;
  tp = strrchr(strin, '.');
  if (tp != NULL) {
    memset(tp + 1, 0, sizeof(char));
  }
  strtemp =
      (char *)malloc(sizeof(char) * strlen(strin) + strlen(extension) + 1);
  strcpy(strtemp, strin);
  strcat(strtemp, extension);
  return (strtemp);
}


x86 assembly (clang, -O0):
<strextension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a1 <strextension+0x41>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
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):
<strextension>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     118d <strextension+0x2d>
add    $0x1,%rax
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strextension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i8* @strrchr(i8* %7, i8 signext 46)
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = call i32 @memset(i8* %13, i32 0, i32 1)
br label %15
15: ; preds = %11, %2
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = add i64 %19, %22
%24 = add i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = load i8*, i8** %3
%30 = call i32 @strcpy(i8* %28, i8* %29)
%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):
define i8* @strextension(i8* %0, i8* %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
%7 = tail call i32 @memset(i8* %6, i32 0, i32 1)
br label %8
8: ; preds = %5, %2
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %1)
%11 = add i32 %9, 1
%12 = add i32 %11, %10
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @strcpy(i8* %14, i8* %0)
%16 = tail call i32 @strcat(i8* %14, i8* %1)
ret i8* %14
}