#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 *);
int /*<<< orphan*/ scanf(char *, int *);
int find(int *stack, int top) {
  int i, query, found = -1;
  printf("\nsearch by value: ");
  scanf("%d", &query);
  for (i = 0; i <= top; i++) {
    if (stack[i] == query) {
      found = i;
      break;
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
lea    0xeca(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1197 <find+0x77>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
jne    1184 <find+0x64>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1197 <find+0x77>
jmp    1189 <find+0x69>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1159 <find+0x39>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    $0xffffffff,%eax
test   %ebx,%ebx
js     1173 <find+0x53>
mov    0x4(%rsp),%ecx
add    $0x1,%ebx
xor    %edx,%edx
nopl   0x0(%rax,%rax,1)
cmp    %ecx,(%r14,%rdx,4)
je     1171 <find+0x51>
add    $0x1,%rdx
cmp    %rdx,%rbx
jne    1160 <find+0x40>
jmp    1173 <find+0x53>
mov    %edx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"\0Asearch by value: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @find(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 -1, i32* %7
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 0, i32* %5
br label %10
10: ; preds = %25, %2
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %15, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %6
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = load i32, i32* %5
store i32 %23, i32* %7
br label %28
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %10
28: ; preds = %22, %10
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@.str = [19 x i8] c"\0Asearch by value: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @find(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%7 = icmp slt i32 %1, 0
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = add nuw i32 %1, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %8, %17
%13 = phi i64 [ 0, %8 ], [ %18, %17 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, %9
br i1 %16, label %20, label %17
17: ; preds = %12
%18 = add nuw nsw i64 %13, 1
%19 = icmp eq i64 %18, %11
br i1 %19, label %22, label %12
20: ; preds = %12
%21 = trunc i64 %13 to i32
br label %22
22: ; preds = %17, %20, %2
%23 = phi i32 [ -1, %2 ], [ %21, %20 ], [ -1, %17 ]
ret i32 %23
}