#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*/ file_move(char *, char *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void file_swap(char *src1, char *src2) {
  int len1 = strlen(src1);
  char name_tmp[len1 + 10];
  strcpy(name_tmp, src1);
  strcat(name_tmp, ".tmp");
  char cmd[len1 * 2 + 10];
  file_move(src1, name_tmp);
  file_move(src2, src1);
  file_move(name_tmp, src2);
  remove(name_tmp);
}


x86 assembly (clang, -O0):
<file_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0xa,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0xa,%eax
mov    %eax,%eax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <file_move@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <file_move@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <file_move@plt>
mov    -0x38(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_swap>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
add    $0xa,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <file_move@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <file_move@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <file_move@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c".tmp\00"
define void @file_swap(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = add nsw i32 %11, 10
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 2
%21 = add nsw i32 %20, 10
%22 = zext i32 %21 to i64
%23 = alloca i8, i64 %22
store i64 %22, i64* %8
%24 = load i8*, i8** %3
%25 = call i32 @file_move(i8* %24, i8* %15)
%26 = load i8*, i8** %4
%27 = load i8*, i8** %3
%28 = call i32 @file_move(i8* %26, i8* %27)
%29 = load i8*, i8** %4
%30 = call i32 @file_move(i8* %15, i8* %29)
%31 = call i32 @remove(i8* %15)
%32 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".tmp\00"
define void @file_swap(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 10
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @strcpy(i8* %6, i8* %0)
%8 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @file_move(i8* %0, i8* %6)
%10 = call i32 @file_move(i8* %1, i8* %0)
%11 = call i32 @file_move(i8* %6, i8* %1)
%12 = call i32 @remove(i8* %6)
ret void
}