#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_(int, int *);
int find_f(int, int *, int);
int find_l(int, int *, int);
void shift_left(int e, int pos, int *arr, int size) {
  int buff, i;
  int pos_e = find_f(e, arr, size);
  int count_e = count_(pos_e, arr);
  for (i = 0; i < count_e; ++i) {
    pos_e = find_l(e, arr, size);
    while (arr[pos + i] != e) {
      buff = arr[pos_e];
      arr[pos_e] = arr[pos_e - 1];
      arr[pos_e - 1] = buff;
      --pos_e;
    }
  }
}


x86 assembly (clang, -O0):
<shift_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <find_f@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <count_@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1201 <shift_left+0xd1>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <find_l@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x4(%rbp),%eax
je     11ee <shift_left+0xbe>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    118b <shift_left+0x5b>
jmp    11f3 <shift_left+0xc3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <shift_left+0x3d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shift_left>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %edi,%ebp
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <find_f@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <count_@plt>
test   %eax,%eax
jle    11c2 <shift_left+0x92>
movslq %r15d,%r15
mov    %eax,%r12d
lea    -0x4(%rbx),%rax
mov    %rax,(%rsp)
xor    %r13d,%r13d
jmp    1189 <shift_left+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    %r12,%r13
je     11c2 <shift_left+0x92>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <find_l@plt>
lea    (%r15,%r13,1),%rcx
cmp    %ebp,(%rbx,%rcx,4)
je     1180 <shift_left+0x50>
movslq %eax,%rdx
mov    (%rbx,%rdx,4),%eax
mov    (%rsp),%rsi
lea    (%rsi,%rdx,4),%rdx
nopl   (%rax)
mov    (%rdx),%esi
mov    %esi,0x4(%rdx)
mov    %eax,(%rdx)
add    $0xfffffffffffffffc,%rdx
cmp    %ebp,(%rbx,%rcx,4)
jne    11b0 <shift_left+0x80>
jmp    1180 <shift_left+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shift_left(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%13 = load i32, i32* %5
%14 = load i32*, i32** %7
%15 = load i32, i32* %8
%16 = call i32 @find_f(i32 %13, i32* %14, i32 %15)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = load i32*, i32** %7
%19 = call i32 @count_(i32 %17, i32* %18)
store i32 %19, i32* %12
store i32 0, i32* %10
br label %20
20: ; preds = %64, %4
%21 = load i32, i32* %10
%22 = load i32, i32* %12
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %67
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32*, i32** %7
%27 = load i32, i32* %8
%28 = call i32 @find_l(i32 %25, i32* %26, i32 %27)
store i32 %28, i32* %11
br label %29
29: ; preds = %39, %24
%30 = load i32*, i32** %7
%31 = load i32, i32* %6
%32 = load i32, i32* %10
%33 = add nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %30, i64 %34
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %63
39: ; preds = %29
%40 = load i32*, i32** %7
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i32, i32* %40, i64 %42
%44 = load i32, i32* %43
store i32 %44, i32* %9
%45 = load i32*, i32** %7
%46 = load i32, i32* %11
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %45, i64 %48
%50 = load i32, i32* %49
%51 = load i32*, i32** %7
%52 = load i32, i32* %11
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32, i32* %51, i64 %53
store i32 %50, i32* %54
%55 = load i32, i32* %9
%56 = load i32*, i32** %7
%57 = load i32, i32* %11
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i32, i32* %56, i64 %59
store i32 %55, i32* %60
%61 = load i32, i32* %11
%62 = add nsw i32 %61, -1
store i32 %62, i32* %11
br label %29
63: ; preds = %29
br label %64
64: ; preds = %63
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %20
67: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @shift_left(i32 %0, i32 %1, i32* %2, i32 %3) {
%5 = tail call i32 @find_f(i32 %0, i32* %2, i32 %3)
%6 = tail call i32 @count_(i32 %5, i32* %2)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %33
8: ; preds = %4
%9 = sext i32 %1 to i64
%10 = zext i32 %6 to i64
br label %11
11: ; preds = %8, %30
%12 = phi i64 [ 0, %8 ], [ %31, %30 ]
%13 = tail call i32 @find_l(i32 %0, i32* %2, i32 %3)
%14 = add nsw i64 %12, %9
%15 = getelementptr inbounds i32, i32* %2, i64 %14
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, %0
br i1 %17, label %30, label %18
18: ; preds = %11
%19 = sext i32 %13 to i64
%20 = getelementptr inbounds i32, i32* %2, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %18, %22
%23 = phi i64 [ %19, %18 ], [ %25, %22 ]
%24 = getelementptr inbounds i32, i32* %2, i64 %23
%25 = add i64 %23, -1
%26 = getelementptr inbounds i32, i32* %2, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %24
store i32 %21, i32* %26
%28 = load i32, i32* %15
%29 = icmp eq i32 %28, %0
br i1 %29, label %30, label %22
30: ; preds = %22, %11
%31 = add nuw nsw i64 %12, 1
%32 = icmp eq i64 %31, %10
br i1 %32, label %33, label %11
33: ; preds = %30, %4
ret void
}