#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*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcasecmp(char *, char *);
int strlen(char *);
char *extend(char *name) {
  static char path[1024];
  int len = strlen(name);
  sprintf(path, "%s%s", name,
          (((len > 4) && !strcasecmp(".bas", name + len - 4)) ? "" : ".bas"));
  return path;
}


x86 assembly (clang, -O0):
<extend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x4,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    1185 <extend+0x55>
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe90(%rip),%rdi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0xd(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0xd(%rbp),%sil
lea    0xe71(%rip),%rcx
lea    0xe69(%rip),%rax
test   $0x1,%sil
cmovne %rax,%rcx
lea    0x2ea6(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <sprintf@plt>
lea    0x2e93(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extend>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x5,%eax
jl     1169 <extend+0x39>
mov    %eax,%eax
lea    (%rbx,%rax,1),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xeb3(%rip),%r14
mov    %r14,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
lea    0xea1(%rip),%rcx
cmovne %r14,%rcx
jmp    1170 <extend+0x40>
lea    0xe95(%rip),%rcx
lea    0x2ed9(%rip),%r14
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@extend.path = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c".bas\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @extend(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 4
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -4
%15 = call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br label %18
18: ; preds = %9, %1
%19 = phi i1 [ false, %1 ], [ %17, %9 ]
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
%22 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @extend.path, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %21)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @extend.path, i64 0, i64 0)
}

LLVM IR (-O2):
@extend.path = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [5 x i8] c".bas\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @extend(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 4
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = zext i32 %2 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -4
%8 = tail call i32 @strcasecmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0)
br label %11
11: ; preds = %4, %1
%12 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %1 ], [ %10, %4 ]
%13 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @extend.path, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %12)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @extend.path, i64 0, i64 0)
}