#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 */
char *str_assign(char *, char *);
char *str_create(char *);
int str_swap(char **str1, char **str2) {
  char *tmpstr = NULL;
  tmpstr = str_create(*str1);
  if (*str1 != NULL && tmpstr == NULL)
    return (0);
  *str1 = str_assign(*str1, *str2);
  *str2 = str_assign(*str2, tmpstr);
  return (1);
}


x86 assembly (clang, -O0):
<str_swap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <str_create@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     116d <str_swap+0x4d>
cmpq   $0x0,-0x20(%rbp)
jne    116d <str_swap+0x4d>
movl   $0x0,-0x4(%rbp)
jmp    11ab <str_swap+0x8b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1040 <str_assign@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <str_assign@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_swap>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1030 <str_create@plt>
mov    %rax,%r15
mov    (%rbx),%rdi
test   %rdi,%rdi
je     1145 <str_swap+0x25>
xor    %eax,%eax
test   %r15,%r15
je     1163 <str_swap+0x43>
mov    (%r14),%rsi
call   1040 <str_assign@plt>
mov    %rax,(%rbx)
mov    (%r14),%rdi
mov    %r15,%rsi
call   1040 <str_assign@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @str_swap(i8** %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8*
store i8** %0, i8*** %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%7 = load i8**, i8*** %4
%8 = load i8*, i8** %7
%9 = call i8* @str_create(i8* %8)
store i8* %9, i8** %6
%10 = load i8**, i8*** %4
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %3
br label %29
17: ; preds = %13, %2
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call i8* @str_assign(i8* %19, i8* %21)
%23 = load i8**, i8*** %4
store i8* %22, i8** %23
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = load i8*, i8** %6
%27 = call i8* @str_assign(i8* %25, i8* %26)
%28 = load i8**, i8*** %5
store i8* %27, i8** %28
store i32 1, i32* %3
br label %29
29: ; preds = %17, %16
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @str_swap(i8** nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %0
%4 = tail call i8* @str_create(i8* %3)
%5 = load i8*, i8** %0
%6 = icmp ne i8* %5, null
%7 = icmp eq i8* %4, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i8* @str_assign(i8* %5, i8* %10)
store i8* %11, i8** %0
%12 = load i8*, i8** %1
%13 = tail call i8* @str_assign(i8* %12, i8* %4)
store i8* %13, i8** %1
br label %14
14: ; preds = %2, %9
%15 = phi i32 [ 1, %9 ], [ 0, %2 ]
ret i32 %15
}