#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 *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strstr(char *, char *);
char *strtok(char *, char *);
void variants_merge(char **variants, char *variants1, char *variants2) {
  char *token;
  int ret, i, j;
  int count;
  char *variants1_dup;
  char *variants2_dup;
  char *variant;
  char *variants_list;
  *variants = malloc(strlen(variants1) + strlen(variants2) + 1 + 1);
  (*variants)[0] = '\0';
  variants1_dup = strdup(variants1);
  variants2_dup = strdup(variants2);
  for (i = 0; i < 2; i++) {
    variants_list = (i == 0) ? variants1_dup : variants2_dup;
    variant = strtok(variants_list, "\x0a");
    while (variant) {
      if (!strstr(*variants, variant)) {
        if ((*variants)[0] != 0) {
          strcat(*variants, "\x0a");
        }
        strcat(*variants, variant);
      }
      variant = strtok(NULL, "\x0a");
    }
  }
  free(variants1_dup);
  free(variants2_dup);
}


x86 assembly (clang, -O0):
<variants_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    12ae <variants_merge+0x13e>
cmpl   $0x0,-0x28(%rbp)
jne    1204 <variants_merge+0x94>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
jmp    120c <variants_merge+0x9c>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     129b <variants_merge+0x12b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x48(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%eax
jne    1282 <variants_merge+0x112>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1272 <variants_merge+0x102>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xd93(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x48(%rbp),%rsi
call   1070 <strcat@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd73(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x48(%rbp)
jmp    1228 <variants_merge+0xb8>
jmp    12a0 <variants_merge+0x130>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e3 <variants_merge+0x73>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<variants_merge>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%r14,%rax,1),%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,0x0(%r13)
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
lea    0xe3a(%rip),%rsi
mov    %r14,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     1221 <variants_merge+0xb1>
mov    %rax,%rbx
lea    0xe23(%rip),%r12
jmp    11fa <variants_merge+0x8a>
nop
mov    %rbx,%rsi
call   1070 <strcat@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1221 <variants_merge+0xb1>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
test   %eax,%eax
jne    11e8 <variants_merge+0x78>
mov    0x0(%r13),%rdi
cmpb   $0x0,(%rdi)
je     11e0 <variants_merge+0x70>
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    0x0(%r13),%rdi
jmp    11e0 <variants_merge+0x70>
lea    0xdd8(%rip),%rsi
mov    %r15,%rdi
call   1060 <strtok@plt>
test   %rax,%rax
je     1291 <variants_merge+0x121>
mov    %rax,%rbx
lea    0xdc1(%rip),%r12
jmp    126a <variants_merge+0xfa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsi
call   1070 <strcat@plt>
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1291 <variants_merge+0x121>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
test   %eax,%eax
jne    1258 <variants_merge+0xe8>
mov    0x0(%r13),%rdi
cmpb   $0x0,(%rdi)
je     1250 <variants_merge+0xe0>
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    0x0(%r13),%rdi
jmp    1250 <variants_merge+0xe0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @variants_merge(i8** %0, i8* %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
%20 = add nsw i64 %17, %19
%21 = add nsw i64 %20, 1
%22 = add nsw i64 %21, 1
%23 = call i8* @malloc(i64 %22)
%24 = load i8**, i8*** %4
store i8* %23, i8** %24
%25 = load i8**, i8*** %4
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 0, i8* %27
%28 = load i8*, i8** %5
%29 = call i8* @strdup(i8* %28)
store i8* %29, i8** %12
%30 = load i8*, i8** %6
%31 = call i8* @strdup(i8* %30)
store i8* %31, i8** %13
store i32 0, i32* %9
br label %32
32: ; preds = %74, %3
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 2
br i1 %34, label %35, label %77
35: ; preds = %32
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i8*, i8** %12
br label %42
40: ; preds = %35
%41 = load i8*, i8** %13
br label %42
42: ; preds = %40, %38
%43 = phi i8* [ %39, %38 ], [ %41, %40 ]
store i8* %43, i8** %15
%44 = load i8*, i8** %15
%45 = call i8* @strtok(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %45, i8** %14
br label %46
46: ; preds = %71, %42
%47 = load i8*, i8** %14
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %73
49: ; preds = %46
%50 = load i8**, i8*** %4
%51 = load i8*, i8** %50
%52 = load i8*, i8** %14
%53 = call i32 @strstr(i8* %51, i8* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %71, label %55
55: ; preds = %49
%56 = load i8**, i8*** %4
%57 = load i8*, i8** %56
%58 = getelementptr inbounds i8, i8* %57, i64 0
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i8**, i8*** %4
%64 = load i8*, i8** %63
%65 = call i32 @strcat(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %66
66: ; preds = %62, %55
%67 = load i8**, i8*** %4
%68 = load i8*, i8** %67
%69 = load i8*, i8** %14
%70 = call i32 @strcat(i8* %68, i8* %69)
br label %71
71: ; preds = %66, %49
%72 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %72, i8** %14
br label %46
73: ; preds = %46
br label %74
74: ; preds = %73
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %32
77: ; preds = %32
%78 = load i8*, i8** %12
%79 = call i32 @free(i8* %78)
%80 = load i8*, i8** %13
%81 = call i32 @free(i8* %80)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @variants_merge(i8** nocapture %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%6 = add i64 %4, 2
%7 = add i64 %6, %5
%8 = tail call i8* @malloc(i64 %7)
store i8* %8, i8** %0
store i8 0, i8* %8
%9 = tail call i8* @strdup(i8* %1)
%10 = tail call i8* @strdup(i8* %2)
%11 = tail call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %31, label %13
13: ; preds = %3, %28
%14 = phi i8* [ %29, %28 ], [ %11, %3 ]
%15 = load i8*, i8** %0
%16 = tail call i32 @strstr(i8* %15, i8* %14)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %28
18: ; preds = %13
%19 = load i8*, i8** %0
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = load i8*, i8** %0
br label %25
25: ; preds = %22, %18
%26 = phi i8* [ %24, %22 ], [ %19, %18 ]
%27 = tail call i32 @strcat(i8* %26, i8* %14)
br label %28
28: ; preds = %25, %13
%29 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %13
31: ; preds = %28, %3
%32 = tail call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i8* %32, null
br i1 %33, label %52, label %34
34: ; preds = %31, %49
%35 = phi i8* [ %50, %49 ], [ %32, %31 ]
%36 = load i8*, i8** %0
%37 = tail call i32 @strstr(i8* %36, i8* %35)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = load i8*, i8** %0
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = tail call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%45 = load i8*, i8** %0
br label %46
46: ; preds = %43, %39
%47 = phi i8* [ %45, %43 ], [ %40, %39 ]
%48 = tail call i32 @strcat(i8* %47, i8* %35)
br label %49
49: ; preds = %46, %34
%50 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %34
52: ; preds = %49, %31
%53 = tail call i32 @free(i8* %9)
%54 = tail call i32 @free(i8* %10)
ret void
}