#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 *findExt(char *);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ uc(char const *);
void append_ext_if_needed(char *file_name, const char *newExt,
                          const char *alsoAllowedExt) {
  char *ext, extuc[1024];
  char new1uc[1024], new2uc[1024];
  ext = findExt(file_name);
  if (ext) {
    strcpy(extuc, uc(ext));
    if (newExt) {
      strcpy(new1uc, uc(newExt));
      if (strcmp(extuc, new1uc) == 0) {
        return;
      }
    }
    if (alsoAllowedExt) {
      strcpy(new2uc, uc(alsoAllowedExt));
      if (strcmp(extuc, new2uc) == 0) {
        return;
      }
    }
  }
  const char *p = newExt;
  if (file_name[strlen(file_name) - 1] == '.')
    ++p;
  if (file_name[strlen(file_name) - 1] != '.' && p[0] != '.')
    strcat(file_name, ".");
  strcat(file_name, p);
}


x86 assembly (clang, -O0):
<append_ext_if_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <findExt@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1267 <append_ext_if_needed+0x107>
lea    -0x420(%rbp),%rax
mov    %rax,-0xc30(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <uc@plt>
mov    -0xc30(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     120b <append_ext_if_needed+0xab>
lea    -0x820(%rbp),%rax
mov    %rax,-0xc38(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <uc@plt>
mov    -0xc38(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1206 <append_ext_if_needed+0xa6>
jmp    1317 <append_ext_if_needed+0x1b7>
jmp    120b <append_ext_if_needed+0xab>
cmpq   $0x0,-0x18(%rbp)
je     1262 <append_ext_if_needed+0x102>
lea    -0xc20(%rbp),%rax
mov    %rax,-0xc40(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <uc@plt>
mov    -0xc40(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    -0xc20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    125d <append_ext_if_needed+0xfd>
jmp    1317 <append_ext_if_needed+0x1b7>
jmp    1262 <append_ext_if_needed+0x102>
jmp    1267 <append_ext_if_needed+0x107>
mov    -0x10(%rbp),%rax
mov    %rax,-0xc28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc48(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xc48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    12b4 <append_ext_if_needed+0x154>
mov    -0xc28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc50(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xc50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1307 <append_ext_if_needed+0x1a7>
mov    -0xc28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1307 <append_ext_if_needed+0x1a7>
mov    -0x8(%rbp),%rdi
lea    0xcfe(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc28(%rbp),%rsi
call   1060 <strcat@plt>
add    $0xc50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_ext_if_needed>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xc08,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1070 <findExt@plt>
test   %rax,%rax
je     11f1 <append_ext_if_needed+0x91>
mov    %rax,%rdi
call   1080 <uc@plt>
mov    %rsp,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
test   %r14,%r14
je     11c2 <append_ext_if_needed+0x62>
mov    %r14,%rdi
call   1080 <uc@plt>
lea    0x800(%rsp),%r12
mov    %r12,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1239 <append_ext_if_needed+0xd9>
test   %r15,%r15
je     11f1 <append_ext_if_needed+0x91>
mov    %r15,%rdi
call   1080 <uc@plt>
lea    0x400(%rsp),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1239 <append_ext_if_needed+0xd9>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0x2e,-0x1(%rax,%rbx,1)
sete   %cl
add    %rcx,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x2e,-0x1(%rax,%rbx,1)
je     122e <append_ext_if_needed+0xce>
cmpb   $0x2e,(%r14)
je     122e <append_ext_if_needed+0xce>
lea    0xdda(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @append_ext_if_needed(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %4
%13 = call i8* @findExt(i8* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %49
16: ; preds = %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = load i8*, i8** %7
%19 = call i32 @uc(i8* %18)
%20 = call i32 @strcpy(i8* %17, i32 %19)
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %34
23: ; preds = %16
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = call i32 @uc(i8* %25)
%27 = call i32 @strcpy(i8* %24, i32 %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%30 = call i64 @strcmp(i8* %28, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
br label %86
33: ; preds = %23
br label %34
34: ; preds = %33, %16
%35 = load i8*, i8** %6
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %48
37: ; preds = %34
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = call i32 @uc(i8* %39)
%41 = call i32 @strcpy(i8* %38, i32 %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%44 = call i64 @strcmp(i8* %42, i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %37
br label %86
47: ; preds = %37
br label %48
48: ; preds = %47, %34
br label %49
49: ; preds = %48, %3
%50 = load i8*, i8** %5
store i8* %50, i8** %11
%51 = load i8*, i8** %4
%52 = load i8*, i8** %4
%53 = call i32 @strlen(i8* %52)
%54 = sub nsw i32 %53, 1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %51, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 46
br i1 %59, label %60, label %63
60: ; preds = %49
%61 = load i8*, i8** %11
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %11
br label %63
63: ; preds = %60, %49
%64 = load i8*, i8** %4
%65 = load i8*, i8** %4
%66 = call i32 @strlen(i8* %65)
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %64, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 46
br i1 %72, label %73, label %82
73: ; preds = %63
%74 = load i8*, i8** %11
%75 = getelementptr inbounds i8, i8* %74, i64 0
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp ne i32 %77, 46
br i1 %78, label %79, label %82
79: ; preds = %73
%80 = load i8*, i8** %4
%81 = call i32 @strcat(i8* %80, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %82
82: ; preds = %79, %73, %63
%83 = load i8*, i8** %4
%84 = load i8*, i8** %11
%85 = call i32 @strcat(i8* %83, i8* %84)
br label %86
86: ; preds = %82, %46, %32
ret void
}

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