#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*/ printf(char *, ...);
int /*<<< orphan*/ swap_str_arr(char *, char *);
int main() {
  char s1[] = "foo";
  char s2[] = "bar bar bar";
  printf("Before swap:\n");
  printf("============\n");
  printf("s1: %s\n", s1);
  printf("s2: %s\n", s2);
  swap_str_arr(s1, s2);
  printf("\nAfter swap:\n");
  printf("============\n");
  printf("s1: %s\n", s1);
  printf("s2: %s\n", s2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xecb(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xec5(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    0xec3(%rip),%eax
mov    %eax,-0xc(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x14(%rbp),%rsi
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <swap_str_arr@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x8(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x14(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x6f6f66,0xc(%rsp)
movabs $0x2072616220726162,%rax
61 72 20
mov    %rax,0x10(%rsp)
movl   $0x726162,0x18(%rsp)
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xec7(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe8e(%rip),%r15
lea    0xc(%rsp),%r13
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%r12
lea    0x10(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <swap_str_arr@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s1 = [4 x i8] c"foo\00"
@__const.main.s2 = [12 x i8] c"bar bar bar\00"
@.str = [14 x i8] c"Before swap:\0A\00"
@.str.1 = [14 x i8] c"============\0A\00"
@.str.2 = [8 x i8] c"s1: %s\0A\00"
@.str.3 = [8 x i8] c"s2: %s\0A\00"
@.str.4 = [14 x i8] c"\0AAfter swap:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca [12 x i8]
store i32 0, i32* %1
%4 = bitcast [4 x i8]* %2 to i8*
%5 = bitcast [12 x i8]* %3 to i8*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%14 = call i32 @swap_str_arr(i8* %12, i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %19)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s2 = [12 x i8] c"bar bar bar\00"
@.str.2 = [8 x i8] c"s1: %s\0A\00"
@.str.3 = [8 x i8] c"s2: %s\0A\00"
@str = [13 x i8] c"Before swap:\00"
@str.6 = [13 x i8] c"\0AAfter swap:\00"
@str.7 = [13 x i8] c"============\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = bitcast i32* %1 to i8*
store i32 7303014, i32* %1
%4 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%9 = call i32 @swap_str_arr(i8* %3, i8* %4)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %4)
ret i32 0
}