#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void intersect_friends(char *str1, char *str2) {
  char *temp = (char *)calloc(40 * 10000, sizeof(char));
  char friend1[10000];
  char friend2[10000];
  {
    if (temp == NULL) {
      fprintf(stderr, "couldnt allocate mem\n");
      exit(1);
    }
  };
  int n1;
  int n2;
  int idx1 = 0;
  int idx2 = 0;
  while (sscanf(&str1[idx1], "%s %n", friend1, &n1) > 0) {
    idx1 += n1;
    idx2 = 0;
    if (idx1 > 10000) {
      ;
      free(temp);
      return;
    }
    while (sscanf(&str2[idx2], "%s %n", friend2, &n2) > 0) {
      idx2 += n2;
      if (idx2 > 10000) {
        ;
        free(temp);
        return;
      }
      if (strcmp(friend1, friend2) == 0) {
        strcat(temp, friend2);
        strcat(temp, " ");
        ;
      }
    }
  };
  strcpy(str1, temp);
  free(temp);
}


x86 assembly (clang, -O0):
<intersect_friends>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x61a80,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d0 <intersect_friends+0x50>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x4e4c(%rbp)
movl   $0x0,-0x4e50(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x4e4c(%rbp),%rax
add    %rax,%rdi
lea    -0x2730(%rbp),%rdx
lea    0xe16(%rip),%rsi
lea    -0x4e44(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jle    12fe <intersect_friends+0x17e>
mov    -0x4e44(%rbp),%eax
add    -0x4e4c(%rbp),%eax
mov    %eax,-0x4e4c(%rbp)
movl   $0x0,-0x4e50(%rbp)
cmpl   $0x2710,-0x4e4c(%rbp)
jle    1250 <intersect_friends+0xd0>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1314 <intersect_friends+0x194>
jmp    1255 <intersect_friends+0xd5>
mov    -0x10(%rbp),%rdi
movslq -0x4e50(%rbp),%rax
add    %rax,%rdi
lea    -0x4e40(%rbp),%rdx
lea    0xda5(%rip),%rsi
lea    -0x4e48(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x0,%rax
jle    12f9 <intersect_friends+0x179>
mov    -0x4e48(%rbp),%eax
add    -0x4e50(%rbp),%eax
mov    %eax,-0x4e50(%rbp)
cmpl   $0x2710,-0x4e50(%rbp)
jle    12b7 <intersect_friends+0x137>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    1314 <intersect_friends+0x194>
lea    -0x2730(%rbp),%rdi
lea    -0x4e40(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12f4 <intersect_friends+0x174>
mov    -0x18(%rbp),%rdi
lea    -0x4e40(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xd2d(%rip),%rsi
call   1090 <strcat@plt>
jmp    1255 <intersect_friends+0xd5>
jmp    11e4 <intersect_friends+0x64>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<intersect_friends>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e38,%rsp
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x61a80,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     12ce <intersect_friends+0x14e>
mov    %rax,%r15
lea    0xe5d(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbp,%rdi
call   1080 <sscanf@plt>
test   %rax,%rax
jle    12a9 <intersect_friends+0x129>
xor    %r14d,%r14d
lea    0xe38(%rip),%r12
lea    0x2720(%rsp),%rbx
mov    %rbp,0x8(%rsp)
jmp    1216 <intersect_friends+0x96>
nopl   (%rax)
mov    %r14,%rdi
mov    0x8(%rsp),%rbp
add    %rbp,%rdi
mov    %r12,%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1080 <sscanf@plt>
test   %rax,%rax
jle    12a9 <intersect_friends+0x129>
movslq 0x4(%rsp),%rax
movslq %r14d,%r14
add    %rax,%r14
cmp    $0x2710,%r14d
jg     12b4 <intersect_friends+0x134>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rsp,%rcx
call   1080 <sscanf@plt>
test   %rax,%rax
jle    11f0 <intersect_friends+0x70>
xor    %ebp,%ebp
jmp    1269 <intersect_friends+0xe9>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
add    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %rsp,%rcx
call   1080 <sscanf@plt>
test   %rax,%rax
jle    11f0 <intersect_friends+0x70>
movslq (%rsp),%rax
movslq %ebp,%rbp
add    %rax,%rbp
cmp    $0x2710,%ebp
jg     12b4 <intersect_friends+0x134>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1250 <intersect_friends+0xd0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %r15,%rdi
lea    0xd7a(%rip),%rsi
call   1090 <strcat@plt>
jmp    1250 <intersect_friends+0xd0>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x4e38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"couldnt allocate mem\0A\00"
@.str.1 = [6 x i8] c"%s %n\00"
@.str.2 = [2 x i8] c" \00"
define void @intersect_friends(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [10000 x i8]
%7 = alloca [10000 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = call i64 @calloc(i32 400000, i32 1)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
store i32 0, i32* %10
store i32 0, i32* %11
br label %21
21: ; preds = %68, %20
%22 = load i8*, i8** %3
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%27 = call i64 @sscanf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32* %8)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %29, label %69
29: ; preds = %21
%30 = load i32, i32* %8
%31 = load i32, i32* %10
%32 = add nsw i32 %31, %30
store i32 %32, i32* %10
store i32 0, i32* %11
%33 = load i32, i32* %10
%34 = icmp sgt i32 %33, 10000
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = load i8*, i8** %5
%37 = call i32 @free(i8* %36)
br label %75
38: ; preds = %29
br label %39
39: ; preds = %67, %38
%40 = load i8*, i8** %4
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%45 = call i64 @sscanf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %44, i32* %9)
%46 = icmp sgt i64 %45, 0
br i1 %46, label %47, label %68
47: ; preds = %39
%48 = load i32, i32* %9
%49 = load i32, i32* %11
%50 = add nsw i32 %49, %48
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = icmp sgt i32 %51, 10000
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = load i8*, i8** %5
%55 = call i32 @free(i8* %54)
br label %75
56: ; preds = %47
%57 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%58 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%59 = call i64 @strcmp(i8* %57, i8* %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = load i8*, i8** %5
%63 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %5
%66 = call i32 @strcat(i8* %65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %67
67: ; preds = %61, %56
br label %39
68: ; preds = %39
br label %21
69: ; preds = %21
%70 = load i8*, i8** %3
%71 = load i8*, i8** %5
%72 = call i32 @strcpy(i8* %70, i8* %71)
%73 = load i8*, i8** %5
%74 = call i32 @free(i8* %73)
br label %75
75: ; preds = %69, %53, %35
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"couldnt allocate mem\0A\00"
@.str.1 = [6 x i8] c"%s %n\00"
@.str.2 = [2 x i8] c" \00"
define void @intersect_friends(i8* %0, i8* %1) {
%3 = alloca [10000 x i8]
%4 = alloca [10000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = tail call i64 @calloc(i32 400000, i32 1)
%8 = inttoptr i64 %7 to i8*
%9 = getelementptr inbounds [10000 x i8], [10000 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%11 = icmp eq i64 %7, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = bitcast i32* %5 to i8*
%18 = bitcast i32* %6 to i8*
%19 = call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* %5)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %26, label %50
21: ; preds = %45, %31
%22 = sext i32 %29 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = call i64 @sscanf(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* %5)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %50
26: ; preds = %16, %21
%27 = phi i32 [ %29, %21 ], [ 0, %16 ]
%28 = load i32, i32* %5
%29 = add nsw i32 %28, %27
%30 = icmp sgt i32 %29, 10000
br i1 %30, label %52, label %31
31: ; preds = %26
%32 = call i64 @sscanf(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32* %6)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %34, label %21
34: ; preds = %31, %45
%35 = phi i32 [ %37, %45 ], [ 0, %31 ]
%36 = load i32, i32* %6
%37 = add nsw i32 %36, %35
%38 = icmp sgt i32 %37, 10000
br i1 %38, label %52, label %39
39: ; preds = %34
%40 = call i64 @strcmp(i8* %9, i8* %10)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = call i32 @strcat(i8* %8, i8* %10)
%44 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %42, %39
%46 = sext i32 %37 to i64
%47 = getelementptr inbounds i8, i8* %1, i64 %46
%48 = call i64 @sscanf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32* %6)
%49 = icmp sgt i64 %48, 0
br i1 %49, label %34, label %21
50: ; preds = %21, %16
%51 = call i32 @strcpy(i8* %0, i8* %8)
br label %52
52: ; preds = %26, %34, %50
%53 = call i32 @free(i8* %8)
ret void
}