void Array_delete(int *arr, int len, int pos) {
  assert(arr);
  assert(len > 0);
  assert(pos < len);
  int i = 0;
  for (i = pos; i < len - 1; i++)
    swap(&arr[i], &arr[i + 1]);
  arr[len - 1] = 0;
}


x86 assembly (clang, -O0):
<Array_delete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1030 <assert@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ba <Array_delete+0x9a>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x0,%al
call   1040 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1172 <Array_delete+0x52>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Array_delete>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
xor    %eax,%eax
call   1030 <assert@plt>
xor    %edi,%edi
cmp    %ebp,%ebx
setl   %dil
xor    %eax,%eax
call   1030 <assert@plt>
add    $0xffffffff,%ebp
cmp    %ebx,%ebp
jle    1189 <Array_delete+0x69>
movslq %ebx,%rax
movslq %ebp,%r15
lea    (%r14,%rax,4),%rdi
mov    %r15,%rbp
sub    %rax,%rbp
nopw   0x0(%rax,%rax,1)
lea    0x4(%rdi),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <swap@plt>
mov    %rbx,%rdi
add    $0xffffffffffffffff,%rbp
jne    1170 <Array_delete+0x50>
jmp    118c <Array_delete+0x6c>
movslq %ebp,%r15
movl   $0x0,(%r14,%r15,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @Array_delete(i32* %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = call i32 (i32*, ...) bitcast (i32 (...)* @assert to i32 (i32*, ...)*)(i32* %8)
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %12)
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
%17 = zext i1 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %17)
store i32 0, i32* %7
%19 = load i32, i32* %6
store i32 %19, i32* %7
br label %20
20: ; preds = %36, %3
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %39
25: ; preds = %20
%26 = load i32*, i32** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32*, i32** %4
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %30, i64 %33
%35 = call i32 (i32*, i32*, ...) bitcast (i32 (...)* @swap to i32 (i32*, i32*, ...)*)(i32* %29, i32* %34)
br label %36
36: ; preds = %25
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %20
39: ; preds = %20
%40 = load i32*, i32** %4
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %40, i64 %43
store i32 0, i32* %44
ret void
}

LLVM IR (-O2):
define void @Array_delete(i32* %0, i32 %1, i32 %2) {
%4 = tail call i32 (i32*, ...) bitcast (i32 (...)* @assert to i32 (i32*, ...)*)(i32* %0)
%5 = icmp sgt i32 %1, 0
%6 = zext i1 %5 to i32
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %6)
%8 = icmp slt i32 %2, %1
%9 = zext i1 %8 to i32
%10 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %9)
%11 = add i32 %1, -1
%12 = icmp sgt i32 %11, %2
br i1 %12, label %15, label %13
13: ; preds = %3
%14 = sext i32 %11 to i64
br label %25
15: ; preds = %3
%16 = sext i32 %2 to i64
%17 = sext i32 %11 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ %16, %15 ], [ %21, %18 ]
%20 = getelementptr inbounds i32, i32* %0, i64 %19
%21 = add nsw i64 %19, 1
%22 = getelementptr inbounds i32, i32* %0, i64 %21
%23 = tail call i32 (i32*, i32*, ...) bitcast (i32 (...)* @swap to i32 (i32*, i32*, ...)*)(i32* %20, i32* %22)
%24 = icmp eq i64 %21, %17
br i1 %24, label %25, label %18
25: ; preds = %18, %13
%26 = phi i64 [ %14, %13 ], [ %17, %18 ]
%27 = getelementptr inbounds i32, i32* %0, i64 %26
store i32 0, i32* %27
ret void
}