#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*/ fprintf(int /*<<< orphan*/, char *, int, int, char *);
int /*<<< orphan*/ piece(char *, char, char *, int);
char *replace_piece(char *, char, char *, int);
int /*<<< orphan*/ stderr;
char *piece_swap(char *source_destination, char delimiter, int piece1_offset,
                 int piece2_offset) {
  char data1[2048], data2[2048];
  if (!piece(data1, delimiter, source_destination, piece1_offset))
    fprintf(stderr, "piece_swap (%d,%d) failed with (%s)\n", piece1_offset,
            piece2_offset, source_destination);
  if (!piece(data2, delimiter, source_destination, piece2_offset))
    fprintf(stderr, "piece_swap (%d,%d) failed with (%s)\n", piece1_offset,
            piece2_offset, source_destination);
  replace_piece(source_destination, delimiter, data2, piece1_offset);
  return replace_piece(source_destination, delimiter, data1, piece2_offset);
}


x86 assembly (clang, -O0):
<piece_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
movsbl %al,%esi
call   1040 <piece@plt>
cmp    $0x0,%eax
jne    118c <piece_swap+0x5c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x9(%rbp),%al
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
movsbl %al,%esi
call   1040 <piece@plt>
cmp    $0x0,%eax
jne    11cd <piece_swap+0x9d>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%r8
lea    0xe38(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x9(%rbp),%al
lea    -0x1020(%rbp),%rdx
mov    -0x10(%rbp),%ecx
movsbl %al,%esi
call   1050 <replace_piece@plt>
mov    -0x8(%rbp),%rdi
mov    -0x9(%rbp),%al
lea    -0x820(%rbp),%rdx
mov    -0x14(%rbp),%ecx
movsbl %al,%esi
call   1050 <replace_piece@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piece_swap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x800(%rsp),%rdi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1040 <piece@plt>
test   %eax,%eax
jne    117d <piece_swap+0x4d>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
movsbl %bpl,%ebp
mov    %rsp,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r14d,%ecx
call   1040 <piece@plt>
test   %eax,%eax
jne    11b3 <piece_swap+0x83>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %rbx,%r8
call   1030 <fprintf@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r15d,%ecx
call   1050 <replace_piece@plt>
lea    0x800(%rsp),%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%ecx
call   1050 <replace_piece@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"piece_swap (%d,%d) failed with (%s)\0A\00"
define i8* @piece_swap(i8* %0, i8 signext %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2048 x i8]
%10 = alloca [2048 x i8]
store i8* %0, i8** %5
store i8 %1, i8* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%12 = load i8, i8* %6
%13 = load i8*, i8** %5
%14 = load i32, i32* %7
%15 = call i32 @piece(i8* %11, i8 signext %12, i8* %13, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %4
%18 = load i32, i32* @stderr
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = load i8*, i8** %5
%22 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20, i8* %21)
br label %23
23: ; preds = %17, %4
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%25 = load i8, i8* %6
%26 = load i8*, i8** %5
%27 = load i32, i32* %8
%28 = call i32 @piece(i8* %24, i8 signext %25, i8* %26, i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = load i32, i32* %7
%33 = load i32, i32* %8
%34 = load i8*, i8** %5
%35 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %33, i8* %34)
br label %36
36: ; preds = %30, %23
%37 = load i8*, i8** %5
%38 = load i8, i8* %6
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%40 = load i32, i32* %7
%41 = call i8* @replace_piece(i8* %37, i8 signext %38, i8* %39, i32 %40)
%42 = load i8*, i8** %5
%43 = load i8, i8* %6
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%45 = load i32, i32* %8
%46 = call i8* @replace_piece(i8* %42, i8 signext %43, i8* %44, i32 %45)
ret i8* %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"piece_swap (%d,%d) failed with (%s)\0A\00"
define i8* @piece_swap(i8* %0, i8 signext %1, i32 %2, i32 %3) {
%5 = alloca [2048 x i8]
%6 = alloca [2048 x i8]
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%9 = call i32 @piece(i8* %7, i8 signext %1, i8* %0, i32 %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i8* %0)
br label %14
14: ; preds = %11, %4
%15 = call i32 @piece(i8* %8, i8 signext %1, i8* %0, i32 %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3, i8* %0)
br label %20
20: ; preds = %17, %14
%21 = call i8* @replace_piece(i8* %0, i8 signext %1, i8* %8, i32 %2)
%22 = call i8* @replace_piece(i8* %0, i8 signext %1, i8* %7, i32 %3)
ret i8* %22
}