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

/* Variables and functions */
int *next_greater_element(int *, size_t, int *, size_t, int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main(void) {
  int nums1[] = {4, 1, 2};
  int nums2[] = {1, 3, 4, 2};
  int i, ret, *ptr;
  size_t len1 = sizeof(nums1) / sizeof(nums1[0]);
  size_t len2 = sizeof(nums2) / sizeof(nums2[0]);
  ptr = next_greater_element(nums1, len1, nums2, len2, &ret);
  for (i = 0; i < ret; i++) {
    printf("%2d, ", ptr[i]);
  }
  puts("");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb8(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x3,-0x38(%rbp)
movq   $0x4,-0x40(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    -0x28(%rbp),%r8
call   1050 <next_greater_element@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11ce <main+0x9e>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <main+0x6d>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0xec9(%rip),%eax
mov    %eax,0x18(%rsp)
mov    0xeb6(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
lea    0x10(%rsp),%rdi
lea    0x20(%rsp),%rdx
lea    0xc(%rsp),%r8
mov    $0x3,%esi
mov    $0x4,%ecx
call   1050 <next_greater_element@plt>
cmpl   $0x0,0xc(%rsp)
jle    11aa <main+0x7a>
mov    %rax,%r15
xor    %ebx,%ebx
lea    0xe94(%rip),%r14
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
cmp    %rax,%rbx
jl     1190 <main+0x60>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.main.nums1 = [3 x i32] [i32 4, i32 1, i32 2]
@__const.main.nums2 = [4 x i32] [i32 1, i32 3, i32 4, i32 2]
@.str = [6 x i8] c"%2d, \00"
define i32 @main() {
%1 = alloca [3 x i32]
%2 = alloca [4 x i32]
%3 = alloca i32
%4 = bitcast [3 x i32]* %1 to i8*
%5 = bitcast [4 x i32]* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%9 = call i32* @next_greater_element(i32* %7, i64 3, i32* %8, i64 4, i32* %3)
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %0, %12
%13 = phi i64 [ %17, %12 ], [ 0, %0 ]
%14 = getelementptr inbounds i32, i32* %9, i64 %13
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = add nuw nsw i64 %13, 1
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %12, label %21
21: ; preds = %12, %0
%22 = call i32 @putchar(i32 10)
ret i32 0
}