#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ swapString(char const **, char const **);
int main(int argc, char **argv) {
  printf("Welcome to PA03.\n"
         "\n"
         "Please make sure that the swapString(...) function works\n"
         "\n");
  printf("Print out some memory addresses for argc, argv...\n"
         "to illustrate how memory is laid out.\n");
  printf("&argc = %p\n", &argc);
  printf("&argv = %p\n", &argv);
  printf("argv = %p\n", argv);
  printf("*argv = %p\n", *argv);
  printf("*argv = %s\n", *argv);
  printf("**argv = %c\n", **argv);
  printf("\nTesting swapString(...)\n");
  const char *str1 = "one";
  const char *str2 = "two";
  printf("Before swap, str1 == %p (i.e., '%s'), "
         "str2 == %p (i.e., '%s')\n",
         str1, str1, str2, str2);
  swapString(&str1, &str2);
  printf("After swap, str1 == %p (i.e., '%s'), "
         "str2 == %p (i.e., '%s')\n",
         str1, str1, str2, str2);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf02(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf4d(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf47(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xf32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%esi
lea    0xf13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf1e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xf17(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xf00(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <swapString@plt>
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xf14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
mov    %edi,0x14(%rsp)
mov    %rsi,0x8(%rsp)
lea    0xf7e(%rip),%rdi
call   1030 <puts@plt>
lea    0xfbe(%rip),%rdi
call   1030 <puts@plt>
lea    0xea4(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
lea    0xe7b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rsi
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%rax
movsbl (%rax),%esi
lea    0xe64(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf8c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe57(%rip),%rdx
mov    %rdx,0x20(%rsp)
lea    0xe4f(%rip),%rcx
mov    %rcx,0x18(%rsp)
lea    0xe47(%rip),%rdi
mov    %rdx,%rsi
mov    %rcx,%r8
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x20(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1040 <swapString@plt>
mov    0x20(%rsp),%rdx
mov    0x18(%rsp),%rcx
lea    0xe59(%rip),%rdi
mov    %rdx,%rsi
mov    %rcx,%r8
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [77 x i8] c"Welcome to PA03.\0A\0APlease make sure that the swapString(...) function works\0A\0A\00"
@.str.1 = [89 x i8] c"Print out some memory addresses for argc, argv...\0Ato illustrate how memory is laid out.\0A\00"
@.str.2 = [12 x i8] c"&argc = %p\0A\00"
@.str.3 = [12 x i8] c"&argv = %p\0A\00"
@.str.4 = [11 x i8] c"argv = %p\0A\00"
@.str.5 = [12 x i8] c"*argv = %p\0A\00"
@.str.6 = [12 x i8] c"*argv = %s\0A\00"
@.str.7 = [13 x i8] c"**argv = %c\0A\00"
@.str.8 = [26 x i8] c"\0ATesting swapString(...)\0A\00"
@.str.9 = [4 x i8] c"one\00"
@.str.10 = [4 x i8] c"two\00"
@.str.11 = [63 x i8] c"Before swap, str1 == %p (i.e., '%s'), str2 == %p (i.e., '%s')\0A\00"
@.str.12 = [62 x i8] c"After swap, str1 == %p (i.e., '%s'), str2 == %p (i.e., '%s')\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([89 x i8], [89 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8*** %5)
%12 = load i8**, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %12)
%14 = load i8**, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8** %7
%26 = load i8*, i8** %6
%27 = load i8*, i8** %6
%28 = load i8*, i8** %7
%29 = load i8*, i8** %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.11, i64 0, i64 0), i8* %26, i8* %27, i8* %28, i8* %29)
%31 = call i32 @swapString(i8** %6, i8** %7)
%32 = load i8*, i8** %6
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = load i8*, i8** %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.12, i64 0, i64 0), i8* %32, i8* %33, i8* %34, i8* %35)
%37 = load i32, i32* @EXIT_SUCCESS
ret i32 %37
}

LLVM IR (-O2):
@.str.2 = [12 x i8] c"&argc = %p\0A\00"
@.str.3 = [12 x i8] c"&argv = %p\0A\00"
@.str.4 = [11 x i8] c"argv = %p\0A\00"
@.str.5 = [12 x i8] c"*argv = %p\0A\00"
@.str.6 = [12 x i8] c"*argv = %s\0A\00"
@.str.7 = [13 x i8] c"**argv = %c\0A\00"
@.str.9 = [4 x i8] c"one\00"
@.str.10 = [4 x i8] c"two\00"
@.str.11 = [63 x i8] c"Before swap, str1 == %p (i.e., '%s'), str2 == %p (i.e., '%s')\0A\00"
@.str.12 = [62 x i8] c"After swap, str1 == %p (i.e., '%s'), str2 == %p (i.e., '%s')\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [76 x i8] c"Welcome to PA03.\0A\0APlease make sure that the swapString(...) function works\0A\00"
@str.13 = [88 x i8] c"Print out some memory addresses for argc, argv...\0Ato illustrate how memory is laid out.\00"
@str.14 = [25 x i8] c"\0ATesting swapString(...)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([76 x i8], [76 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @str.13, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8*** %4)
%11 = load i8**, i8*** %4
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %11)
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %4
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %17)
%19 = load i8**, i8*** %4
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.14, i64 0, i64 0))
%25 = bitcast i8** %5 to i8*
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8** %5
%26 = bitcast i8** %6 to i8*
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8** %6
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%28 = call i32 @swapString(i8** %5, i8** %6)
%29 = load i8*, i8** %5
%30 = load i8*, i8** %6
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.12, i64 0, i64 0), i8* %29, i8* %29, i8* %30, i8* %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}