#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 *);
char *ft_strjoin(char *, char *);
char *ft_strjoinfree(char *s1, char *s2, int mode) {
  char *tmp;
  tmp = ft_strjoin(s1, s2);
  if (mode == 1)
    free(s1);
  else if (mode == 2)
    free(s2);
  else {
    free(s1);
    free(s2);
  }
  return (tmp);
}


x86 assembly (clang, -O0):
<ft_strjoinfree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ft_strjoin@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    115c <ft_strjoinfree+0x3c>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
jmp    118b <ft_strjoinfree+0x6b>
cmpl   $0x2,-0x14(%rbp)
jne    1174 <ft_strjoinfree+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1186 <ft_strjoinfree+0x66>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    118b <ft_strjoinfree+0x6b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strjoinfree>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <ft_strjoin@plt>
mov    %rax,%r14
cmp    $0x1,%ebp
je     114b <ft_strjoinfree+0x2b>
cmp    $0x2,%ebp
je     114e <ft_strjoinfree+0x2e>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    114e <ft_strjoinfree+0x2e>
mov    %rbx,%r15
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @ft_strjoinfree(i8* %0, i8* %1, i32 %2) {
%4 = tail call i8* @ft_strjoin(i8* %0, i8* %1)
switch i32 %2, label %6 [
i32 1, label %8
i32 2, label %5
]
5: ; preds = %3
br label %8
6: ; preds = %3
%7 = tail call i32 @free(i8* %0)
br label %8
8: ; preds = %3, %5, %6
%9 = phi i8* [ %1, %5 ], [ %1, %6 ], [ %0, %3 ]
%10 = tail call i32 @free(i8* %9)
ret i8* %4
}