#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 count_number_in_array(int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
void print_last_ele_in_array(int *p, int n, int pos) {
  int i;
  int array[20] = {};
  int *temp = array;
  int *q = array;
  while (count_number_in_array(q, 20, 0) > 1) {
    while (*q != 1 && ((pos - 1) > 0)) {
      while (*(q + 1) == 1) {
        q++;
        if (q == temp + 20)
          ;
        q = temp;
      }
      q++;
      if (q == temp + 20)
        ;
      q = temp;
      pos--;
    }
    *q = 1;
  }
  printf("%d\n", *q);
}


x86 assembly (clang, -O0):
<print_last_ele_in_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1040 <memset@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    $0x14,%esi
xor    %edx,%edx
call   1050 <count_number_in_array@plt>
cmp    $0x1,%eax
jle    124e <print_last_ele_in_array+0x11e>
jmp    1183 <print_last_ele_in_array+0x53>
mov    -0x80(%rbp),%rcx
xor    %eax,%eax
cmpl   $0x1,(%rcx)
mov    %al,-0x81(%rbp)
je     11aa <print_last_ele_in_array+0x7a>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
cmp    $0x0,%eax
setg   %al
mov    %al,-0x81(%rbp)
mov    -0x81(%rbp),%al
test   $0x1,%al
jne    11bd <print_last_ele_in_array+0x8d>
jmp    123f <print_last_ele_in_array+0x10f>
jmp    11c2 <print_last_ele_in_array+0x92>
mov    -0x80(%rbp),%rax
cmpl   $0x1,0x4(%rax)
jne    1203 <print_last_ele_in_array+0xd3>
mov    -0x80(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
add    $0x50,%rcx
cmp    %rcx,%rax
jne    11f6 <print_last_ele_in_array+0xc6>
jmp    11f6 <print_last_ele_in_array+0xc6>
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    11c2 <print_last_ele_in_array+0x92>
mov    -0x80(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x78(%rbp),%rcx
add    $0x50,%rcx
cmp    %rcx,%rax
jne    1229 <print_last_ele_in_array+0xf9>
jmp    1229 <print_last_ele_in_array+0xf9>
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <print_last_ele_in_array+0x53>
mov    -0x80(%rbp),%rax
movl   $0x1,(%rax)
jmp    1165 <print_last_ele_in_array+0x35>
mov    -0x80(%rbp),%rax
mov    (%rax),%esi
lea    0xda5(%rip),%rdi
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_last_ele_in_array>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %edx,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x14,%esi
xor    %edx,%edx
call   1040 <count_number_in_array@plt>
cmp    $0x2,%eax
jl     11a2 <print_last_ele_in_array+0x82>
mov    %rsp,%r14
jmp    117b <print_last_ele_in_array+0x5b>
nopl   (%rax)
movl   $0x1,(%rsp)
mov    %r14,%rdi
mov    $0x14,%esi
xor    %edx,%edx
call   1040 <count_number_in_array@plt>
cmp    $0x1,%eax
jle    11a2 <print_last_ele_in_array+0x82>
cmpl   $0x1,(%rsp)
je     1160 <print_last_ele_in_array+0x40>
cmp    $0x2,%ebx
jl     1160 <print_last_ele_in_array+0x40>
mov    $0x1,%ebx
cmpl   $0x1,0x4(%rsp)
jne    1160 <print_last_ele_in_array+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
jmp    11a0 <print_last_ele_in_array+0x80>
mov    (%rsp),%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @print_last_ele_in_array(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x i32]
%9 = alloca i32*
%10 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = bitcast [20 x i32]* %8 to i8*
%12 = getelementptr inbounds [20 x i32], [20 x i32]* %8, i64 0, i64 0
store i32* %12, i32** %9
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %8, i64 0, i64 0
store i32* %13, i32** %10
br label %14
14: ; preds = %57, %3
%15 = load i32*, i32** %10
%16 = call i32 @count_number_in_array(i32* %15, i32 20, i32 0)
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %59
18: ; preds = %14
br label %19
19: ; preds = %53, %18
%20 = load i32*, i32** %10
%21 = load i32, i32* %20
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 1
%26 = icmp sgt i32 %25, 0
br label %27
27: ; preds = %23, %19
%28 = phi i1 [ false, %19 ], [ %26, %23 ]
br i1 %28, label %29, label %57
29: ; preds = %27
br label %30
30: ; preds = %43, %29
%31 = load i32*, i32** %10
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %45
35: ; preds = %30
%36 = load i32*, i32** %10
%37 = getelementptr inbounds i32, i32* %36, i32 1
store i32* %37, i32** %10
%38 = load i32*, i32** %10
%39 = load i32*, i32** %9
%40 = getelementptr inbounds i32, i32* %39, i64 20
%41 = icmp eq i32* %38, %40
br i1 %41, label %42, label %43
42: ; preds = %35
br label %43
43: ; preds = %42, %35
%44 = load i32*, i32** %9
store i32* %44, i32** %10
br label %30
45: ; preds = %30
%46 = load i32*, i32** %10
%47 = getelementptr inbounds i32, i32* %46, i32 1
store i32* %47, i32** %10
%48 = load i32*, i32** %10
%49 = load i32*, i32** %9
%50 = getelementptr inbounds i32, i32* %49, i64 20
%51 = icmp eq i32* %48, %50
br i1 %51, label %52, label %53
52: ; preds = %45
br label %53
53: ; preds = %52, %45
%54 = load i32*, i32** %9
store i32* %54, i32** %10
%55 = load i32, i32* %6
%56 = add nsw i32 %55, -1
store i32 %56, i32* %6
br label %19
57: ; preds = %27
%58 = load i32*, i32** %10
store i32 1, i32* %58
br label %14
59: ; preds = %14
%60 = load i32*, i32** %10
%61 = load i32, i32* %60
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %61)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @print_last_ele_in_array(i32* nocapture readnone %0, i32 %1, i32 %2) {
%4 = alloca [20 x i32]
%5 = bitcast [20 x i32]* %4 to i8*
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 0
%7 = call i32 @count_number_in_array(i32* %6, i32 20, i32 0)
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %25
9: ; preds = %3
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %4, i64 0, i64 1
br label %11
11: ; preds = %9, %21
%12 = phi i32 [ %2, %9 ], [ %22, %21 ]
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 1
%15 = icmp sgt i32 %12, 1
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* %10
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %17, %20
br label %20
21: ; preds = %17, %11
%22 = phi i32 [ %12, %11 ], [ 1, %17 ]
store i32 1, i32* %6
%23 = call i32 @count_number_in_array(i32* %6, i32 20, i32 0)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %11, label %25
25: ; preds = %21, %3
%26 = load i32, i32* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %26)
ret void
}