#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, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
void ex2() {
  int n, pick, verify = 0, tmp, x;
  do {
    puts("Informe o numero de valores:");
    scanf("%d", &n);
  } while (n <= 0);
  int array[n];
  for (x = 0; x < n; x++) {
    printf("Informe o %d valor:\n", x + 1);
    scanf("%d", &array[x]);
  }
  puts("Informe o valor desejado:");
  scanf("%d", &pick);
  for (x = 0; x < n; x++) {
    if (array[x] == pick) {
      verify = 1;
      break;
    }
  }
  if (verify == 1) {
    printf("o numero %d esta na posicao %d do vetor e foi o %d numero a ser "
           "informado\n",
           pick, x, x + 1);
  } else {
    printf("o numero %d nao esta no vetor\n", pick);
  }
}


x86 assembly (clang, -O0):
<ex2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <puts@plt>
lea    0xecb(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
jle    113f <ex2+0xf>
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11dc <ex2+0xac>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe54(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <ex2+0x63>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    123e <ex2+0x10e>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x8(%rbp),%eax
jne    122b <ex2+0xfb>
movl   $0x1,-0xc(%rbp)
jmp    123e <ex2+0x10e>
jmp    1230 <ex2+0x100>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ff <ex2+0xcf>
cmpl   $0x1,-0xc(%rbp)
jne    1267 <ex2+0x137>
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1278 <ex2+0x148>
mov    -0x8(%rbp),%esi
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ex2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%r14
lea    0xece(%rip),%r15
lea    -0x2c(%rbp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    1160 <ex2+0x30>
mov    %rsp,-0x38(%rbp)
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11d8 <ex2+0xa8>
lea    0xe80(%rip),%r14
lea    0xe76(%rip),%r15
mov    %r13,%r12
xor    %ebx,%ebx
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movslq -0x2c(%rbp),%rax
add    $0x4,%r12
cmp    %rax,%rbx
jl     11b0 <ex2+0x80>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
lea    0xe32(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
mov    -0x30(%rbp),%esi
test   %eax,%eax
jle    1210 <ex2+0xe0>
xor    %edx,%edx
cmp    %esi,0x0(%r13,%rdx,4)
je     1220 <ex2+0xf0>
add    $0x1,%rdx
cmp    %rdx,%rax
jne    1200 <ex2+0xd0>
lea    0xe83(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1231 <ex2+0x101>
lea    0x1(%rdx),%ecx
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Informe o numero de valores:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Informe o %d valor:\0A\00"
@.str.3 = [26 x i8] c"Informe o valor desejado:\00"
@.str.4 = [75 x i8] c"o numero %d esta na posicao %d do vetor e foi o %d numero a ser informado\0A\00"
@.str.5 = [31 x i8] c"o numero %d nao esta no vetor\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
br label %8
8: ; preds = %11, %0
%9 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
br label %11
11: ; preds = %8
%12 = load i32, i32* %1
%13 = icmp sle i32 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %11
%15 = load i32, i32* %1
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %6
%18 = alloca i32, i64 %16
store i64 %16, i64* %7
store i32 0, i32* %5
br label %19
19: ; preds = %31, %14
%20 = load i32, i32* %5
%21 = load i32, i32* %1
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %19
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %18, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %23
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %19
34: ; preds = %19
%35 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
store i32 0, i32* %5
br label %37
37: ; preds = %50, %34
%38 = load i32, i32* %5
%39 = load i32, i32* %1
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %18, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* %2
%47 = icmp eq i32 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %41
store i32 1, i32* %3
br label %53
49: ; preds = %41
br label %50
50: ; preds = %49
%51 = load i32, i32* %5
%52 = add nsw i32 %51, 1
store i32 %52, i32* %5
br label %37
53: ; preds = %48, %37
%54 = load i32, i32* %3
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %62
56: ; preds = %53
%57 = load i32, i32* %2
%58 = load i32, i32* %5
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %57, i32 %58, i32 %60)
br label %65
62: ; preds = %53
%63 = load i32, i32* %2
%64 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %56
%66 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Informe o numero de valores:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Informe o %d valor:\0A\00"
@.str.3 = [26 x i8] c"Informe o valor desejado:\00"
@.str.4 = [75 x i8] c"o numero %d esta na posicao %d do vetor e foi o %d numero a ser informado\0A\00"
@.str.5 = [31 x i8] c"o numero %d nao esta no vetor\0A\00"
define void @ex2() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %5, %0
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = zext i32 %8 to i64
%12 = call i8* @llvm.stacksave()
%13 = alloca i32, i64 %11
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %10, %16
%17 = phi i64 [ %18, %16 ], [ 0, %10 ]
%18 = add nuw nsw i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds i32, i32* %13, i64 %17
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %21)
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %18, %24
br i1 %25, label %16, label %26
26: ; preds = %16, %10
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%29 = load i32, i32* %1
%30 = icmp sgt i32 %29, 0
%31 = load i32, i32* %2
br i1 %30, label %32, label %46
32: ; preds = %26
%33 = zext i32 %29 to i64
br label %34
34: ; preds = %32, %39
%35 = phi i64 [ 0, %32 ], [ %40, %39 ]
%36 = getelementptr inbounds i32, i32* %13, i64 %35
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, %31
br i1 %38, label %42, label %39
39: ; preds = %34
%40 = add nuw nsw i64 %35, 1
%41 = icmp eq i64 %40, %33
br i1 %41, label %46, label %34
42: ; preds = %34
%43 = trunc i64 %35 to i32
%44 = add nuw nsw i32 %43, 1
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.4, i64 0, i64 0), i32 %31, i32 %43, i32 %44)
br label %48
46: ; preds = %39, %26
%47 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i32 %31)
br label %48
48: ; preds = %46, %42
ret void
}