#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strrchr(char *, char);
int addFileExtention(char *filename, char *extension) {
  char *ptr;
  if (!filename)
    return (0);
  if (!extension)
    return (0);
  if (ptr = (char *)strrchr(filename, '.')) {
    if (extension[0] == '.')
      strcpy(ptr, extension);
    else
      strcpy(++ptr, extension);
  } else {
    if (extension[0] == '.')
      strcat(filename, extension);
    else {
      strcat(filename, ".");
      strcat(filename, extension);
    }
  }
  return (1);
}


x86 assembly (clang, -O0):
<addFileExtention>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1157 <addFileExtention+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1211 <addFileExtention+0xe1>
cmpq   $0x0,-0x18(%rbp)
jne    116e <addFileExtention+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1211 <addFileExtention+0xe1>
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c6 <addFileExtention+0x96>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ac <addFileExtention+0x7c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11c1 <addFileExtention+0x91>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    120a <addFileExtention+0xda>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e8 <addFileExtention+0xb8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1205 <addFileExtention+0xd5>
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
jmp    120a <addFileExtention+0xda>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addFileExtention>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
test   %rdi,%rdi
je     1192 <addFileExtention+0x62>
mov    %rsi,%r14
test   %rsi,%rsi
je     1192 <addFileExtention+0x62>
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1040 <strrchr@plt>
mov    (%r14),%cl
test   %rax,%rax
je     116e <addFileExtention+0x3e>
cmp    $0x2e,%cl
je     1161 <addFileExtention+0x31>
add    $0x1,%rax
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    118d <addFileExtention+0x5d>
cmp    $0x2e,%cl
je     1182 <addFileExtention+0x52>
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define i32 @addFileExtention(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i32 0, i32* %3
br label %53
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i32 0, i32* %3
br label %53
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i64 @strrchr(i8* %15, i8 signext 46)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %35
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 46
br i1 %24, label %25, label %29
25: ; preds = %19
%26 = load i8*, i8** %6
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %34
29: ; preds = %19
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
%32 = load i8*, i8** %5
%33 = call i32 @strcpy(i8* %31, i8* %32)
br label %34
34: ; preds = %29, %25
br label %52
35: ; preds = %14
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 46
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = load i8*, i8** %5
%44 = call i32 @strcat(i8* %42, i8* %43)
br label %51
45: ; preds = %35
%46 = load i8*, i8** %4
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%48 = load i8*, i8** %4
%49 = load i8*, i8** %5
%50 = call i32 @strcat(i8* %48, i8* %49)
br label %51
51: ; preds = %45, %41
br label %52
52: ; preds = %51, %34
store i32 1, i32* %3
br label %53
53: ; preds = %52, %13, %9
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @addFileExtention(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = tail call i64 @strrchr(i8* %0, i8 signext 46)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 46
br i1 %9, label %18, label %12
12: ; preds = %6
br i1 %11, label %13, label %15
13: ; preds = %12
%14 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %24
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %8, i64 1
%17 = tail call i32 @strcpy(i8* %16, i8* %1)
br label %24
18: ; preds = %6
br i1 %11, label %19, label %21
19: ; preds = %18
%20 = tail call i32 @strcat(i8* %0, i8* %1)
br label %24
21: ; preds = %18
%22 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = tail call i32 @strcat(i8* %0, i8* %1)
br label %24
24: ; preds = %15, %13, %21, %19, %2
%25 = phi i32 [ 0, %2 ], [ 1, %19 ], [ 1, %21 ], [ 1, %13 ], [ 1, %15 ]
ret i32 %25
}