#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 *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void addext(char *filename, char *ext) {
  int l = strlen(filename);
  if (l >= 16) {
    strcpy(filename + 11, ext);
    return;
  }
  if (strcmp(filename + l - 4, ext) != 0) {
    strcat(filename, ext);
    l = strlen(filename);
    if (l >= 16) {
      strcpy(filename + 11, ext);
      return;
    }
  }
}


x86 assembly (clang, -O0):
<addext>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jl     117c <addext+0x3c>
mov    -0x8(%rbp),%rdi
add    $0xb,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11dc <addext+0x9c>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11dc <addext+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x10,-0x14(%rbp)
jl     11d7 <addext+0x97>
mov    -0x8(%rbp),%rdi
add    $0xb,%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11dc <addext+0x9c>
jmp    11dc <addext+0x9c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addext>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0xf,%eax
jg     1183 <addext+0x43>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1199 <addext+0x59>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x10,%eax
jl     1199 <addext+0x59>
add    $0xb,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @addext(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 16
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 11
%13 = load i8*, i8** %4
%14 = call i32 @strcpy(i8* %12, i8* %13)
br label %38
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -4
%21 = load i8*, i8** %4
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %38
24: ; preds = %15
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %5
%30 = load i32, i32* %5
%31 = icmp sge i32 %30, 16
br i1 %31, label %32, label %37
32: ; preds = %24
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 11
%35 = load i8*, i8** %4
%36 = call i32 @strcpy(i8* %34, i8* %35)
br label %38
37: ; preds = %24
br label %38
38: ; preds = %10, %32, %37, %15
ret void
}

LLVM IR (-O2):
define void @addext(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 15
br i1 %4, label %15, label %5
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = getelementptr inbounds i8, i8* %7, i64 -4
%9 = tail call i64 @strcmp(i8* %8, i8* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %18, label %11
11: ; preds = %5
%12 = tail call i32 @strcat(i8* %0, i8* %1)
%13 = tail call i32 @strlen(i8* %0)
%14 = icmp sgt i32 %13, 15
br i1 %14, label %15, label %18
15: ; preds = %11, %2
%16 = getelementptr inbounds i8, i8* %0, i64 11
%17 = tail call i32 @strcpy(i8* %16, i8* %1)
br label %18
18: ; preds = %15, %5, %11
ret void
}