#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*/ free(char *);
scalar_t__ malloc(unsigned int);
char *strncpy(char *, char *, unsigned int);
int __BNF_swap(char *first, char *second, char *third) {
  unsigned len1 = second - first, len2 = third - second;
  char *hold = strncpy((char *)malloc(len1 + 1), first, len1);
  strncpy(first, second, len2);
  strncpy(first + len2, hold, len1);
  free(hold);
  return 0;
}


x86 assembly (clang, -O0):
<__BNF_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%eax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__BNF_swap>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    %r12d,%ebx
sub    %r14d,%ebx
sub    %rsi,%r15
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
mov    %rax,%r13
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <strncpy@plt>
mov    %r15d,%edi
add    %r14,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <strncpy@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @__BNF_swap(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %5
%11 = load i8*, i8** %4
%12 = ptrtoint i8* %10 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
store i32 %15, i32* %7
%16 = load i8*, i8** %6
%17 = load i8*, i8** %5
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
store i32 %21, i32* %8
%22 = load i32, i32* %7
%23 = add i32 %22, 1
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load i8*, i8** %4
%27 = load i32, i32* %7
%28 = call i8* @strncpy(i8* %25, i8* %26, i32 %27)
store i8* %28, i8** %9
%29 = load i8*, i8** %4
%30 = load i8*, i8** %5
%31 = load i32, i32* %8
%32 = call i8* @strncpy(i8* %29, i8* %30, i32 %31)
%33 = load i8*, i8** %4
%34 = load i32, i32* %8
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8*, i8** %9
%38 = load i32, i32* %7
%39 = call i8* @strncpy(i8* %36, i8* %37, i32 %38)
%40 = load i8*, i8** %9
%41 = call i32 @free(i8* %40)
ret i32 0
}

LLVM IR (-O2):
define i32 @__BNF_swap(i8* %0, i8* %1, i8* %2) {
%4 = ptrtoint i8* %1 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %4, %5
%7 = trunc i64 %6 to i32
%8 = ptrtoint i8* %2 to i64
%9 = sub i64 %8, %4
%10 = trunc i64 %9 to i32
%11 = add i32 %7, 1
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = tail call i8* @strncpy(i8* %13, i8* %0, i32 %7)
%15 = tail call i8* @strncpy(i8* %0, i8* %1, i32 %10)
%16 = and i64 %9, 4294967295
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = tail call i8* @strncpy(i8* %17, i8* %14, i32 %7)
%19 = tail call i32 @free(i8* %14)
ret i32 0
}