#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 */
struct link {
  int dummy;
};

/* Variables and functions */
scalar_t__ equal_link(struct link *, int, int, int, int);
int /*<<< orphan*/ printf(char *);
int remove_pos(int, int, struct link **);
int remove_elem(int lft, int rgt, int syn, int lftarc, int s,
                struct link **stack) {
  int i, j;
  for (i = s - 1; i >= 0; i--) {
    if (equal_link(stack[i], lft, rgt, syn, lftarc)) {
      s = remove_pos(i, s, stack);
      return s;
    }
  }
  printf("error: elem not in stack\n");
  return s;
}


x86 assembly (clang, -O0):
<remove_elem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11b7 <remove_elem+0x87>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1050 <equal_link@plt>
cmp    $0x0,%rax
je     11a4 <remove_elem+0x74>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1040 <remove_pos@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <remove_elem+0x99>
jmp    11a9 <remove_elem+0x79>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1155 <remove_elem+0x25>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_elem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %ecx,%r12d
mov    %edx,%r13d
mov    %esi,%ebx
mov    %edi,%r14d
mov    %r8d,0x4(%rsp)
mov    %r8d,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    119e <remove_elem+0x6e>
mov    -0x8(%r15,%rbp,8),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %r13d,%ecx
mov    %r12d,%r8d
call   1050 <equal_link@plt>
add    $0xffffffffffffffff,%rbp
test   %rax,%rax
je     1160 <remove_elem+0x30>
mov    %ebp,%edi
mov    0x4(%rsp),%esi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <remove_pos@plt>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i32 }
@.str = [26 x i8] c"error: elem not in stack\0A\00"
define i32 @remove_elem(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, %struct.link** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.link**
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store %struct.link** %5, %struct.link*** %13
%16 = load i32, i32* %12
%17 = sub nsw i32 %16, 1
store i32 %17, i32* %14
br label %18
18: ; preds = %40, %6
%19 = load i32, i32* %14
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = load %struct.link**, %struct.link*** %13
%23 = load i32, i32* %14
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds %struct.link*, %struct.link** %22, i64 %24
%26 = load %struct.link*, %struct.link** %25
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i32, i32* %11
%31 = call i64 @equal_link(%struct.link* %26, i32 %27, i32 %28, i32 %29, i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %21
%34 = load i32, i32* %14
%35 = load i32, i32* %12
%36 = load %struct.link**, %struct.link*** %13
%37 = call i32 @remove_pos(i32 %34, i32 %35, %struct.link** %36)
store i32 %37, i32* %12
%38 = load i32, i32* %12
store i32 %38, i32* %7
br label %46
39: ; preds = %21
br label %40
40: ; preds = %39
%41 = load i32, i32* %14
%42 = add nsw i32 %41, -1
store i32 %42, i32* %14
br label %18
43: ; preds = %18
%44 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%45 = load i32, i32* %12
store i32 %45, i32* %7
br label %46
46: ; preds = %43, %33
%47 = load i32, i32* %7
ret i32 %47
}

LLVM IR (-O2):
%struct.link = type { i32 }
@str = [25 x i8] c"error: elem not in stack\00"
define i32 @remove_elem(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, %struct.link** %5) {
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %13, %6
%9 = phi i64 [ %10, %13 ], [ %7, %6 ]
%10 = add nsw i64 %9, -1
%11 = trunc i64 %9 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %8
%14 = getelementptr inbounds %struct.link*, %struct.link** %5, i64 %10
%15 = load %struct.link*, %struct.link** %14
%16 = tail call i64 @equal_link(%struct.link* %15, i32 %0, i32 %1, i32 %2, i32 %3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %8, label %18
18: ; preds = %13
%19 = trunc i64 %10 to i32
%20 = tail call i32 @remove_pos(i32 %19, i32 %4, %struct.link** %5)
br label %23
21: ; preds = %8
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
%24 = phi i32 [ %20, %18 ], [ %4, %21 ]
ret i32 %24
}