#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 *format_string(char *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ same_string(char *, char *);
char *strdup(char *);
void merge_string(char **a, char **b) {
  char *s1 = *a, *s2 = *b;
  if (!s2)
    return;
  if (same_string(s1, s2))
    return;
  if (!s1) {
    *a = strdup(s2);
    return;
  }
  *a = format_string("(%s) or (%s)", s1, s2);
  free(s1);
}


x86 assembly (clang, -O0):
<merge_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1176 <merge_string+0x36>
jmp    11dc <merge_string+0x9c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <same_string@plt>
cmp    $0x0,%rax
je     1192 <merge_string+0x52>
jmp    11dc <merge_string+0x9c>
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <merge_string+0x75>
mov    -0x20(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    11dc <merge_string+0x9c>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe3c(%rip),%rdi
call   1050 <format_string@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge_string>:
push   %r15
push   %r14
push   %rbx
mov    (%rsi),%rbx
test   %rbx,%rbx
je     1163 <merge_string+0x23>
mov    %rdi,%r14
mov    (%rdi),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <same_string@plt>
test   %rax,%rax
je     1169 <merge_string+0x29>
pop    %rbx
pop    %r14
pop    %r15
ret
test   %r15,%r15
je     1190 <merge_string+0x50>
lea    0xe8b(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1050 <format_string@plt>
mov    %rax,(%r14)
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>
mov    %rbx,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r14)
jmp    1163 <merge_string+0x23>

LLVM IR (-O0):
@.str = [13 x i8] c"(%s) or (%s)\00"
define void @merge_string(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
store i8** %0, i8*** %3
store i8** %1, i8*** %4
%7 = load i8**, i8*** %3
%8 = load i8*, i8** %7
store i8* %8, i8** %5
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
br label %34
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = load i8*, i8** %6
%17 = call i64 @same_string(i8* %15, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14
br label %34
20: ; preds = %14
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = call i8* @strdup(i8* %24)
%26 = load i8**, i8*** %3
store i8* %25, i8** %26
br label %34
27: ; preds = %20
%28 = load i8*, i8** %5
%29 = load i8*, i8** %6
%30 = call i8* @format_string(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
%31 = load i8**, i8*** %3
store i8* %30, i8** %31
%32 = load i8*, i8** %5
%33 = call i32 @free(i8* %32)
br label %34
34: ; preds = %27, %23, %19, %13
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"(%s) or (%s)\00"
define void @merge_string(i8** nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %0
%4 = load i8*, i8** %1
%5 = icmp eq i8* %4, null
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = tail call i64 @same_string(i8* %3, i8* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %6
%10 = icmp eq i8* %3, null
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i8* @strdup(i8* %4)
store i8* %12, i8** %0
br label %16
13: ; preds = %9
%14 = tail call i8* @format_string(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4)
store i8* %14, i8** %0
%15 = tail call i32 @free(i8* %3)
br label %16
16: ; preds = %6, %2, %13, %11
ret void
}