#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 strlen(char *);
int /*<<< orphan*/ *strrchr(char *, char);
void get_fn(char *dest, char *src, char *ext) {
  register int i;
  register char *sp, *dp;
  i = 0;
  sp = src;
  dp = dest;
  while ((i++ < 2048) && (*sp != '\0'))
    *dp++ = *sp++;
  *dp = '\0';
  if ((strrchr(dest, '.') == NULL) && (strlen(dest) <= (2048 - strlen(ext))))
    strcat(dest, ext);
}


x86 assembly (clang, -O0):
<get_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    $0x800,%ecx
mov    %al,-0x31(%rbp)
jge    1187 <get_fn+0x57>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1197 <get_fn+0x67>
jmp    11be <get_fn+0x8e>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    115b <get_fn+0x2b>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
cmp    $0x0,%rax
jne    1213 <get_fn+0xe3>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
mov    -0x38(%rbp),%eax
mov    $0x800,%ecx
sub    %edx,%ecx
cmp    %ecx,%eax
jg     1213 <get_fn+0xe3>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fn>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
xor    %eax,%eax
nopl   0x0(%rax)
movzbl (%rsi,%rax,1),%ecx
test   %cl,%cl
je     117d <get_fn+0x4d>
mov    %cl,(%rbx,%rax,1)
movzbl 0x1(%rsi,%rax,1),%ecx
test   %cl,%cl
je     1182 <get_fn+0x52>
mov    %cl,0x1(%rbx,%rax,1)
movzbl 0x2(%rsi,%rax,1),%ecx
test   %cl,%cl
je     118b <get_fn+0x5b>
mov    %cl,0x2(%rbx,%rax,1)
movzbl 0x3(%rsi,%rax,1),%ecx
test   %cl,%cl
je     1194 <get_fn+0x64>
mov    %cl,0x3(%rbx,%rax,1)
add    $0x4,%rax
cmp    $0x800,%eax
jne    1140 <get_fn+0x10>
add    %rbx,%rax
jmp    119b <get_fn+0x6b>
add    %rbx,%rax
add    $0x1,%rax
jmp    119b <get_fn+0x6b>
add    %rbx,%rax
add    $0x2,%rax
jmp    119b <get_fn+0x6b>
add    %rbx,%rax
add    $0x3,%rax
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
jne    11cd <get_fn+0x9d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    $0x800,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebp
jle    11d2 <get_fn+0xa2>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rbx,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <strcat@plt>

LLVM IR (-O0):
define void @get_fn(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%10 = load i8*, i8** %5
store i8* %10, i8** %8
%11 = load i8*, i8** %4
store i8* %11, i8** %9
br label %12
12: ; preds = %23, %3
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 1
store i32 %14, i32* %7
%15 = icmp slt i32 %13, 2048
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8*, i8** %8
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
br i1 %22, label %23, label %29
23: ; preds = %21
%24 = load i8*, i8** %8
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %8
%26 = load i8, i8* %24
%27 = load i8*, i8** %9
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %9
store i8 %26, i8* %27
br label %12
29: ; preds = %21
%30 = load i8*, i8** %9
store i8 0, i8* %30
%31 = load i8*, i8** %4
%32 = call i32* @strrchr(i8* %31, i8 signext 46)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %45
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = call i32 @strlen(i8* %35)
%37 = load i8*, i8** %6
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 2048, %38
%40 = icmp sle i32 %36, %39
br i1 %40, label %41, label %45
41: ; preds = %34
%42 = load i8*, i8** %4
%43 = load i8*, i8** %6
%44 = call i32 @strcat(i8* %42, i8* %43)
br label %45
45: ; preds = %41, %34, %29
ret void
}

LLVM IR (-O2):
define void @get_fn(i8* %0, i8* nocapture %1, i8* %2) {
br label %4
4: ; preds = %25, %3
%5 = phi i32 [ 1, %3 ], [ %28, %25 ]
%6 = phi i8* [ %0, %3 ], [ %27, %25 ]
%7 = phi i8* [ %1, %3 ], [ %26, %25 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %30, label %10
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %8, i8* %6
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %10
%16 = getelementptr inbounds i8, i8* %7, i64 2
%17 = getelementptr inbounds i8, i8* %6, i64 2
store i8 %13, i8* %12
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 0
br i1 %19, label %30, label %20
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %7, i64 3
%22 = getelementptr inbounds i8, i8* %6, i64 3
store i8 %18, i8* %17
%23 = load i8, i8* %21
%24 = icmp eq i8 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %7, i64 4
%27 = getelementptr inbounds i8, i8* %6, i64 4
store i8 %23, i8* %22
%28 = add nuw nsw i32 %5, 4
%29 = icmp eq i32 %28, 2049
br i1 %29, label %30, label %4
30: ; preds = %25, %20, %15, %10, %4
%31 = phi i8* [ %6, %4 ], [ %12, %10 ], [ %17, %15 ], [ %22, %20 ], [ %27, %25 ]
store i8 0, i8* %31
%32 = tail call i32* @strrchr(i8* %0, i8 signext 46)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = tail call i32 @strlen(i8* %0)
%36 = tail call i32 @strlen(i8* %2)
%37 = sub nsw i32 2048, %36
%38 = icmp sgt i32 %35, %37
br i1 %38, label %41, label %39
39: ; preds = %34
%40 = tail call i32 @strcat(i8* %0, i8* %2)
br label %41
41: ; preds = %39, %34, %30
ret void
}