#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 binary_search(int *, int, int, int);
scalar_t__ malloc(int);
int *two_sum(int *numbers, int numbers_size, int target) {
  int search;
  for (int a = 0; a < numbers_size; a++) {
    search = binary_search(numbers, numbers_size, target - numbers[a], a);
    if (search >= 0) {
      int *ret = (int *)malloc(2 * sizeof(int));
      ret[0] = a;
      ret[1] = search;
      return ret;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<two_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b0 <two_sum+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
sub    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%ecx
call   1040 <binary_search@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     119d <two_sum+0x7d>
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <two_sum+0x98>
jmp    11a2 <two_sum+0x82>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1139 <two_sum+0x19>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<two_sum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1163 <two_sum+0x43>
mov    %edx,%r15d
mov    %rdi,%r12
mov    %esi,%r13d
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15d,%edx
sub    (%r12,%rbx,4),%edx
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%ecx
call   1040 <binary_search@plt>
test   %eax,%eax
jns    1168 <two_sum+0x48>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1140 <two_sum+0x20>
jmp    117c <two_sum+0x5c>
xor    %r14d,%r14d
jmp    117c <two_sum+0x5c>
mov    %eax,%ebp
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
mov    %ebx,(%rax)
mov    %ebp,0x4(%rax)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32* @two_sum(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %9
br label %11
11: ; preds = %40, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %43
15: ; preds = %11
%16 = load i32*, i32** %5
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = load i32*, i32** %5
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = sub nsw i32 %18, %23
%25 = load i32, i32* %9
%26 = call i32 @binary_search(i32* %16, i32 %17, i32 %24, i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %15
%30 = call i64 @malloc(i32 8)
%31 = inttoptr i64 %30 to i32*
store i32* %31, i32** %10
%32 = load i32, i32* %9
%33 = load i32*, i32** %10
%34 = getelementptr inbounds i32, i32* %33, i64 0
store i32 %32, i32* %34
%35 = load i32, i32* %8
%36 = load i32*, i32** %10
%37 = getelementptr inbounds i32, i32* %36, i64 1
store i32 %35, i32* %37
%38 = load i32*, i32** %10
store i32* %38, i32** %4
br label %44
39: ; preds = %15
br label %40
40: ; preds = %39
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %11
43: ; preds = %11
store i32* null, i32** %4
br label %44
44: ; preds = %43, %29
%45 = load i32*, i32** %4
ret i32* %45
}

LLVM IR (-O2):
define i32* @two_sum(i32* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %23
5: ; preds = %3
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %20
%8 = phi i64 [ 0, %5 ], [ %21, %20 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = sub nsw i32 %2, %10
%12 = trunc i64 %8 to i32
%13 = tail call i32 @binary_search(i32* %0, i32 %1, i32 %11, i32 %12)
%14 = icmp sgt i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %7
%16 = trunc i64 %8 to i32
%17 = tail call i64 @malloc(i32 8)
%18 = inttoptr i64 %17 to i32*
store i32 %16, i32* %18
%19 = getelementptr inbounds i32, i32* %18, i64 1
store i32 %13, i32* %19
br label %23
20: ; preds = %7
%21 = add nuw nsw i64 %8, 1
%22 = icmp eq i64 %21, %6
br i1 %22, label %23, label %7
23: ; preds = %20, %3, %15
%24 = phi i32* [ %18, %15 ], [ null, %3 ], [ null, %20 ]
ret i32* %24
}