#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 */
typedef int /*<<< orphan*/ nums;

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, int);
int *searchRange(int *, int, int, int *);
void searchRangeMain(void) {
  int nums[] = {7, 7, 7, 8, 8, 10};
  int numsSize = sizeof(nums) / sizeof(nums[0]);
  int returnSize = 0;
  int *result = searchRange(nums, numsSize, 7, &returnSize);
  for (; returnSize > 0; returnSize--) {
    printf("%d\n", result[returnSize - 1]);
  }
  free(result);
}


x86 assembly (clang, -O0):
<searchRangeMain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xebe(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xebb(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x6,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0x7,%edx
lea    -0x28(%rbp),%rcx
call   1050 <searchRange@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11b4 <searchRangeMain+0x84>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1180 <searchRangeMain+0x50>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<searchRangeMain>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0xed2(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xeb6(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rcx
mov    $0x6,%esi
mov    $0x7,%edx
call   1050 <searchRange@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11ae <searchRangeMain+0x7e>
lea    0xe96(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0xffffffff,%eax
mov    (%rbx,%rax,4),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%ecx
lea    -0x1(%rcx),%eax
mov    %eax,0xc(%rsp)
cmp    $0x1,%ecx
jg     1190 <searchRangeMain+0x60>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.searchRangeMain.nums = [6 x i32] [i32 7, i32 7, i32 7, i32 8, i32 8, i32 10]
@.str = [4 x i8] c"%d\0A\00"
define void @searchRangeMain() {
%1 = alloca [6 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = bitcast [6 x i32]* %1 to i8*
store i32 6, i32* %2
store i32 0, i32* %3
%6 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%7 = load i32, i32* %2
%8 = call i32* @searchRange(i32* %6, i32 %7, i32 7, i32* %3)
store i32* %8, i32** %4
br label %9
9: ; preds = %20, %0
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32*, i32** %4
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %13, i64 %16
%18 = load i32, i32* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %12
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
br label %9
23: ; preds = %9
%24 = load i32*, i32** %4
%25 = call i32 @free(i32* %24)
ret void
}

LLVM IR (-O2):
@__const.searchRangeMain.nums = [6 x i32] [i32 7, i32 7, i32 7, i32 8, i32 8, i32 10]
@.str = [4 x i8] c"%d\0A\00"
define void @searchRangeMain() {
%1 = alloca [6 x i32]
%2 = alloca i32
%3 = bitcast [6 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = getelementptr inbounds [6 x i32], [6 x i32]* %1, i64 0, i64 0
%6 = call i32* @searchRange(i32* %5, i32 6, i32 7, i32* %2)
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %0, %9
%10 = phi i32 [ %17, %9 ], [ %7, %0 ]
%11 = add nsw i32 %10, -1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i32, i32* %6, i64 %12
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, -1
store i32 %17, i32* %2
%18 = icmp sgt i32 %16, 1
br i1 %18, label %9, label %19
19: ; preds = %9, %0
%20 = call i32 @free(i32* %6)
ret void
}