#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 findx(int *, int, int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
  int X = 0;
  int first = 0;
  int second = 0;
  int size = 9;
  int ret;
  printf("Input Array :");
  for (int i = 0; i < size; i++) {
    printf("%d ", A[i]);
  }
  printf("Enter X, we will find two elements whose sum is X:");
  scanf("%d", &X);
  ret = findx(A, size, &first, &second, X);
  if (ret) {
    printf("A[%d= %d] + A[%d= %d]= %d\n", first, A[first], second, A[second],
           X);
  } else {
    printf("No match found\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x24,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x9,-0x50(%rbp)
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    11cc <main+0x8c>
movslq -0x58(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    119c <main+0x5c>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x44(%rbp),%rsi
call   1060 <scanf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%esi
mov    -0x44(%rbp),%r8d
lea    -0x48(%rbp),%rdx
lea    -0x4c(%rbp),%rcx
call   1030 <findx@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     123d <main+0xfd>
mov    -0x48(%rbp),%esi
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
mov    -0x4c(%rbp),%ecx
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%r8d
mov    -0x44(%rbp),%r9d
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124b <main+0x10b>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    0xed5(%rip),%eax
mov    %eax,0x30(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x4(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe39(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%r8d
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    $0x9,%esi
call   1040 <findx@plt>
test   %eax,%eax
je     1284 <main+0x144>
movslq 0xc(%rsp),%rsi
mov    0x10(%rsp,%rsi,4),%edx
movslq 0x8(%rsp),%rcx
mov    0x10(%rsp,%rcx,4),%r8d
mov    0x4(%rsp),%r9d
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1290 <main+0x150>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.A = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [14 x i8] c"Input Array :\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [51 x i8] c"Enter X, we will find two elements whose sum is X:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [27 x i8] c"A[%d= %d] + A[%d= %d]= %d\0A\00"
@.str.5 = [16 x i8] c"No match found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [9 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [9 x i32]* %6 to i8*
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 9, i32* %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %12
br label %15
15: ; preds = %25, %2
%16 = load i32, i32* %12
%17 = load i32, i32* %10
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %28
19: ; preds = %15
%20 = load i32, i32* %12
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %19
%26 = load i32, i32* %12
%27 = add nsw i32 %26, 1
store i32 %27, i32* %12
br label %15
28: ; preds = %15
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%31 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = call i32 @findx(i32* %31, i32 %32, i32* %8, i32* %9, i32 %33)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %50
37: ; preds = %28
%38 = load i32, i32* %8
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = load i32, i32* %9
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [9 x i32], [9 x i32]* %6, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %38, i32 %42, i32 %43, i32 %47, i32 %48)
br label %52
50: ; preds = %28
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %52
52: ; preds = %50, %37
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@__const.main.A = [9 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9]
@.str = [14 x i8] c"Input Array :\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [51 x i8] c"Enter X, we will find two elements whose sum is X:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [27 x i8] c"A[%d= %d] + A[%d= %d]= %d\0A\00"
@str = [15 x i8] c"No match found\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [9 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast [9 x i32]* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 0
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 5)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 6)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 7)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 8)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 9)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%24 = load i32, i32* %4
%25 = call i32 @findx(i32* %12, i32 9, i32* %5, i32* %6, i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %2
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [9 x i32], [9 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = load i32, i32* %4
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %28, i32 %31, i32 %32, i32 %35, i32 %36)
br label %40
38: ; preds = %2
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %38, %27
ret i32 0
}