#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 *build123Array(int);
int *build123ArrayBaseVal(int, int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ memcpy(int *, int *, int);
int missingElement(int *, int);
int /*<<< orphan*/ outArrInt(int *, int);
int /*<<< orphan*/ printf(char *, int);
void testMissingElement() {
  int size1 = 10, size2 = 20;
  int *elems = (int *)calloc(sizeof(int), size1 + size2);
  int *elems1 = build123Array(size1);
  int *elems2 = build123ArrayBaseVal(size2, size1 + 1);
  memcpy(elems, elems1, sizeof(int) * size1);
  memcpy(elems + size1, elems2, sizeof(int) * size2);
  outArrInt(elems, size1 + size2);
  printf("missing element in array = %d\n",
         missingElement(elems, size1 + size2));
  free(elems);
  free(elems1);
  free(elems2);
}


x86 assembly (clang, -O0):
<testMissingElement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xa,-0x4(%rbp)
movl   $0x14,-0x8(%rbp)
mov    -0x4(%rbp),%esi
add    -0x8(%rbp),%esi
mov    $0x4,%edi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <build123Array@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
add    $0x1,%esi
call   10a0 <build123ArrayBaseVal@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
add    -0x8(%rbp),%esi
call   1090 <outArrInt@plt>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
add    -0x8(%rbp),%esi
call   1040 <missingElement@plt>
mov    %eax,%esi
lea    0xdd8(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testMissingElement>:
push   %r15
push   %r14
push   %rbx
mov    $0x4,%edi
mov    $0x1e,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
mov    $0xa,%edi
call   1080 <build123Array@plt>
mov    %rax,%r14
mov    $0x14,%edi
mov    $0xb,%esi
call   10a0 <build123ArrayBaseVal@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
lea    0x28(%rbx),%rdi
mov    %r15,%rsi
mov    $0x50,%edx
call   1070 <memcpy@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1090 <outArrInt@plt>
mov    %rbx,%rdi
mov    $0x1e,%esi
call   1040 <missingElement@plt>
lea    0xe08(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"missing element in array = %d\0A\00"
define void @testMissingElement() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
store i32 10, i32* %1
store i32 20, i32* %2
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = add nsw i32 %6, %7
%9 = call i64 @calloc(i32 4, i32 %8)
%10 = inttoptr i64 %9 to i32*
store i32* %10, i32** %3
%11 = load i32, i32* %1
%12 = call i32* @build123Array(i32 %11)
store i32* %12, i32** %4
%13 = load i32, i32* %2
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
%16 = call i32* @build123ArrayBaseVal(i32 %13, i32 %15)
store i32* %16, i32** %5
%17 = load i32*, i32** %3
%18 = load i32*, i32** %4
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @memcpy(i32* %17, i32* %18, i32 %22)
%24 = load i32*, i32** %3
%25 = load i32, i32* %1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32*, i32** %5
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = mul i64 4, %30
%32 = trunc i64 %31 to i32
%33 = call i32 @memcpy(i32* %27, i32* %28, i32 %32)
%34 = load i32*, i32** %3
%35 = load i32, i32* %1
%36 = load i32, i32* %2
%37 = add nsw i32 %35, %36
%38 = call i32 @outArrInt(i32* %34, i32 %37)
%39 = load i32*, i32** %3
%40 = load i32, i32* %1
%41 = load i32, i32* %2
%42 = add nsw i32 %40, %41
%43 = call i32 @missingElement(i32* %39, i32 %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = load i32*, i32** %3
%46 = call i32 @free(i32* %45)
%47 = load i32*, i32** %4
%48 = call i32 @free(i32* %47)
%49 = load i32*, i32** %5
%50 = call i32 @free(i32* %49)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"missing element in array = %d\0A\00"
define void @testMissingElement() {
%1 = tail call i64 @calloc(i32 4, i32 30)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i32* @build123Array(i32 10)
%4 = tail call i32* @build123ArrayBaseVal(i32 20, i32 11)
%5 = tail call i32 @memcpy(i32* %2, i32* %3, i32 40)
%6 = getelementptr inbounds i32, i32* %2, i64 10
%7 = tail call i32 @memcpy(i32* %6, i32* %4, i32 80)
%8 = tail call i32 @outArrInt(i32* %2, i32 30)
%9 = tail call i32 @missingElement(i32* %2, i32 30)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @free(i32* %2)
%12 = tail call i32 @free(i32* %3)
%13 = tail call i32 @free(i32* %4)
ret void
}