#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 *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *make_swp(char *file) {
  char *swp = malloc(strlen(file) + 6);
  int i;
  i = strlen(file) - 1;
  while (i > 0 && file[i - 1] != '/')
    i--;
  strncpy(swp, file, i);
  swp[i] = '.';
  strcpy(&swp[i + 1], &file[i]);
  strcpy(&swp[strlen(file) + 1], ".swp");
  return swp;
}


x86 assembly (clang, -O0):
<make_swp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x6,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    119b <make_swp+0x5b>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11ab <make_swp+0x6b>
jmp    11b9 <make_swp+0x79>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <make_swp+0x32>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%eax
cltq
add    %rax,%rdi
lea    0xde8(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_swp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x6(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0x1,%ebp
cmovle %eax,%ebp
lea    -0x1(%rbp),%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x2,%ecx
jl     1198 <make_swp+0x58>
lea    -0x2(%rcx),%eax
add    $0xffffffffffffffff,%rcx
cmpb   $0x2f,(%rbx,%rax,1)
jne    1180 <make_swp+0x40>
lea    0x1(%rcx),%ebp
mov    %ecx,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movslq %r15d,%rsi
movb   $0x2e,(%r14,%rsi,1)
movslq %ebp,%rdi
add    %r14,%rdi
add    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rax,%r14,1),%rdi
add    $0x1,%rdi
lea    0xe2b(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".swp\00"
define i8* @make_swp(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 6
%4 = tail call i8* @malloc(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = zext i32 %5 to i64
%7 = call i32 @llvm.smin.i32(i32 %5, i32 1)
%8 = add i32 %7, -1
br label %9
9: ; preds = %14, %1
%10 = phi i64 [ %11, %14 ], [ %6, %1 ]
%11 = add nsw i64 %10, -1
%12 = trunc i64 %10 to i32
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = add i64 %10, 4294967294
%16 = and i64 %15, 4294967295
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 47
br i1 %19, label %20, label %9
20: ; preds = %14
%21 = trunc i64 %10 to i32
%22 = trunc i64 %11 to i32
br label %23
23: ; preds = %9, %20
%24 = phi i32 [ %21, %20 ], [ %7, %9 ]
%25 = phi i32 [ %22, %20 ], [ %8, %9 ]
%26 = tail call i32 @strncpy(i8* %4, i8* %0, i32 %25)
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %4, i64 %27
store i8 46, i8* %28
%29 = sext i32 %24 to i64
%30 = getelementptr inbounds i8, i8* %4, i64 %29
%31 = getelementptr inbounds i8, i8* %0, i64 %27
%32 = tail call i32 @strcpy(i8* %30, i8* %31)
%33 = tail call i32 @strlen(i8* %0)
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %4, i64 %35
%37 = tail call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret i8* %4
}