#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 Context {
  int dummy;
};

/* Variables and functions */
long pop_to_long();
int /*<<< orphan*/ push_from_long(long);
void builtin_minus(struct Context *ctx, unsigned int stack_track) {
  if (stack_track == 0) {
    push_from_long(0L);
    return;
  }
  if (stack_track == 1) {
    push_from_long(-(pop_to_long()));
    return;
  }
  long result = pop_to_long();
  for (stack_track--; stack_track; stack_track--)
    result -= pop_to_long();
  push_from_long(result);
}


x86 assembly (clang, -O0):
<builtin_minus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <builtin_minus+0x27>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <push_from_long@plt>
jmp    11b3 <builtin_minus+0x93>
cmpl   $0x1,-0xc(%rbp)
jne    1169 <builtin_minus+0x49>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
xor    %ecx,%ecx
mov    %ecx,%edi
sub    %rax,%rdi
call   1040 <push_from_long@plt>
jmp    11b3 <builtin_minus+0x93>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11aa <builtin_minus+0x8a>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <builtin_minus+0x5d>
mov    -0x18(%rbp),%rdi
call   1040 <push_from_long@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_minus>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
je     113d <builtin_minus+0x1d>
mov    %esi,%ebp
xor    %eax,%eax
cmp    $0x1,%esi
jne    1141 <builtin_minus+0x21>
call   1030 <pop_to_long@plt>
mov    %rax,%rbx
neg    %rbx
jmp    115f <builtin_minus+0x3f>
xor    %ebx,%ebx
jmp    115f <builtin_minus+0x3f>
call   1030 <pop_to_long@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <pop_to_long@plt>
sub    %rax,%rbx
add    $0xffffffff,%ebp
jne    1150 <builtin_minus+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <push_from_long@plt>

LLVM IR (-O0):
%struct.Context = type { i32 }
define void @builtin_minus(%struct.Context* %0, i32 %1) {
%3 = alloca %struct.Context*
%4 = alloca i32
%5 = alloca i64
store %struct.Context* %0, %struct.Context** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @push_from_long(i64 0)
br label %34
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i64 (...) @pop_to_long()
%15 = sub nsw i64 0, %14
%16 = call i32 @push_from_long(i64 %15)
br label %34
17: ; preds = %10
%18 = call i64 (...) @pop_to_long()
store i64 %18, i64* %5
%19 = load i32, i32* %4
%20 = add i32 %19, -1
store i32 %20, i32* %4
br label %21
21: ; preds = %28, %17
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %21
%25 = call i64 (...) @pop_to_long()
%26 = load i64, i64* %5
%27 = sub nsw i64 %26, %25
store i64 %27, i64* %5
br label %28
28: ; preds = %24
%29 = load i32, i32* %4
%30 = add i32 %29, -1
store i32 %30, i32* %4
br label %21
31: ; preds = %21
%32 = load i64, i64* %5
%33 = call i32 @push_from_long(i64 %32)
br label %34
34: ; preds = %31, %13, %8
ret void
}

LLVM IR (-O2):
%struct.Context = type { i32 }
define void @builtin_minus(%struct.Context* nocapture readnone %0, i32 %1) {
switch i32 %1, label %6 [
i32 0, label %16
i32 1, label %3
]
3: ; preds = %2
%4 = tail call i64 (...) @pop_to_long()
%5 = sub nsw i64 0, %4
br label %16
6: ; preds = %2
%7 = tail call i64 (...) @pop_to_long()
%8 = add i32 %1, -1
br label %9
9: ; preds = %6, %9
%10 = phi i32 [ %14, %9 ], [ %8, %6 ]
%11 = phi i64 [ %13, %9 ], [ %7, %6 ]
%12 = tail call i64 (...) @pop_to_long()
%13 = sub nsw i64 %11, %12
%14 = add i32 %10, -1
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %9
16: ; preds = %9, %2, %3
%17 = phi i64 [ %5, %3 ], [ 0, %2 ], [ %13, %9 ]
%18 = tail call i32 @push_from_long(i64 %17)
ret void
}