#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 *);
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *check_extension(const char *string, const char *ext) {
  char *new = 0;
  if (strchr(string, '.') == 0) {
    new = (char *)malloc(strlen(string) + strlen(ext) + 1);
    assert(new != 0);
    strcpy(new, string);
    strcat(new, ext);
  } else {
    new = (char *)malloc(strlen(string) + 1);
    assert(new != 0);
    strcpy(new, string);
  }
  return new;
}


x86 assembly (clang, -O0):
<check_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    11eb <check_extension+0x8b>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%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
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1223 <check_extension+0xc3>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %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
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_extension>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
test   %r12,%r12
je     11b5 <check_extension+0x55>
add    $0x1,%rbx
mov    %rbx,%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
call   1030 <strcpy@plt>
jmp    11f1 <check_extension+0x91>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%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
call   1030 <strcpy@plt>
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):
define i8* @check_extension(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i64 @strchr(i8* %6, i8 signext 46)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i64 @strlen(i8* %10)
%12 = load i8*, i8** %4
%13 = call i64 @strlen(i8* %12)
%14 = add nsw i64 %11, %13
%15 = add nsw i64 %14, 1
%16 = call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i8*, i8** %5
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %25, i8* %26)
br label %41
28: ; preds = %2
%29 = load i8*, i8** %3
%30 = call i64 @strlen(i8* %29)
%31 = add nsw i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %5
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, null
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
%38 = load i8*, i8** %5
%39 = load i8*, i8** %3
%40 = call i32 @strcpy(i8* %38, i8* %39)
br label %41
41: ; preds = %28, %9
%42 = load i8*, i8** %5
ret i8* %42
}

LLVM IR (-O2):
define i8* @check_extension(i8* %0, i8* %1) {
%3 = tail call i64 @strchr(i8* %0, i8 signext 46)
%4 = icmp eq i64 %3, 0
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
br i1 %4, label %6, label %17
6: ; preds = %2
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = add i64 %5, 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 @strcpy(i8* %11, i8* %0)
%16 = tail call i32 @strcat(i8* %11, i8* %1)
br label %25
17: ; preds = %2
%18 = add nsw i64 %5, 1
%19 = tail call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
%21 = icmp ne i64 %19, 0
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i32 @strcpy(i8* %20, i8* %0)
br label %25
25: ; preds = %17, %6
%26 = phi i8* [ %11, %6 ], [ %20, %17 ]
ret i8* %26
}