#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*/ printf(char *, ...);
void arrayIntersection() {
  int array1[10] = {5, 6, 2, 3, 7, 8, 1, 12, 34, 9};
  int array2[5] = {2, 3, 1, 4, 6};
  int intersectionArray[5] = {0};
  int index = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 10; j++) {
      if (array2[i] == array1[j]) {
        intersectionArray[index] = array2[i];
        index++;
        break;
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    if (intersectionArray[i] != 0) {
      printf("%d  ", intersectionArray[i]);
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<arrayIntersection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x30(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
mov    0xed9(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xed6(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xed4(%rip),%eax
mov    %eax,-0x40(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movl   $0x0,-0x74(%rbp)
movl   $0x0,-0x78(%rbp)
cmpl   $0x5,-0x78(%rbp)
jge    1202 <arrayIntersection+0xd2>
movl   $0x0,-0x7c(%rbp)
cmpl   $0xa,-0x7c(%rbp)
jge    11ef <arrayIntersection+0xbf>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
movslq -0x7c(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
jne    11dc <arrayIntersection+0xac>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%ecx
movslq -0x74(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11ef <arrayIntersection+0xbf>
jmp    11e1 <arrayIntersection+0xb1>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    119e <arrayIntersection+0x6e>
jmp    11f4 <arrayIntersection+0xc4>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    118d <arrayIntersection+0x5d>
movl   $0x0,-0x80(%rbp)
cmpl   $0x5,-0x80(%rbp)
jge    124b <arrayIntersection+0x11b>
movslq -0x80(%rbp),%rax
cmpl   $0x0,-0x70(%rbp,%rax,4)
je     1238 <arrayIntersection+0x108>
movslq -0x80(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123d <arrayIntersection+0x10d>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    1209 <arrayIntersection+0xd9>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrayIntersection>:
push   %rbx
lea    0xed8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@__const.arrayIntersection.array1 = [10 x i32] [i32 5, i32 6, i32 2, i32 3, i32 7, i32 8, i32 1, i32 12, i32 34, i32 9]
@__const.arrayIntersection.array2 = [5 x i32] [i32 2, i32 3, i32 1, i32 4, i32 6]
@.str = [5 x i8] c"%d \00"
@.str.1 = [2 x i8] c"\0A\00"
define void @arrayIntersection() {
%1 = alloca [10 x i32]
%2 = alloca [5 x i32]
%3 = alloca [5 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast [10 x i32]* %1 to i8*
%9 = bitcast [5 x i32]* %2 to i8*
%10 = bitcast [5 x i32]* %3 to i8*
store i32 0, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %43, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 5
br i1 %13, label %14, label %46
14: ; preds = %11
store i32 0, i32* %6
br label %15
15: ; preds = %39, %14
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %42
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %22, %26
br i1 %27, label %28, label %38
28: ; preds = %18
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %34
store i32 %32, i32* %35
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %42
38: ; preds = %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %15
42: ; preds = %28, %15
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %11
46: ; preds = %11
store i32 0, i32* %7
br label %47
47: ; preds = %63, %46
%48 = load i32, i32* %7
%49 = icmp slt i32 %48, 5
br i1 %49, label %50, label %66
50: ; preds = %47
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %50
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [5 x i32], [5 x i32]* %3, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %56, %50
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %47
66: ; preds = %47
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d \00"
define void @arrayIntersection() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 2)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 3)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 6)
%5 = tail call i32 @putchar(i32 10)
ret void
}