#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_mult(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_mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <builtin_mult+0x27>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <push_from_long@plt>
jmp    11aa <builtin_mult+0x8a>
cmpl   $0x1,-0xc(%rbp)
jne    1165 <builtin_mult+0x45>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,%rdi
call   1040 <push_from_long@plt>
jmp    11aa <builtin_mult+0x8a>
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     11a1 <builtin_mult+0x81>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
imul   -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <builtin_mult+0x59>
mov    -0x18(%rbp),%rdi
call   1040 <push_from_long@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_mult>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
je     113a <builtin_mult+0x1a>
mov    %esi,%ebp
xor    %eax,%eax
cmp    $0x1,%esi
jne    113e <builtin_mult+0x1e>
call   1030 <pop_to_long@plt>
mov    %rax,%rbx
jmp    1160 <builtin_mult+0x40>
xor    %ebx,%ebx
jmp    1160 <builtin_mult+0x40>
call   1030 <pop_to_long@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <pop_to_long@plt>
imul   %rax,%rbx
add    $0xffffffff,%ebp
jne    1150 <builtin_mult+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_mult(%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 %33
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i64 (...) @pop_to_long()
%15 = call i32 @push_from_long(i64 %14)
br label %33
16: ; preds = %10
%17 = call i64 (...) @pop_to_long()
store i64 %17, i64* %5
%18 = load i32, i32* %4
%19 = add i32 %18, -1
store i32 %19, i32* %4
br label %20
20: ; preds = %27, %16
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = call i64 (...) @pop_to_long()
%25 = load i64, i64* %5
%26 = mul nsw i64 %25, %24
store i64 %26, i64* %5
br label %27
27: ; preds = %23
%28 = load i32, i32* %4
%29 = add i32 %28, -1
store i32 %29, i32* %4
br label %20
30: ; preds = %20
%31 = load i64, i64* %5
%32 = call i32 @push_from_long(i64 %31)
br label %33
33: ; preds = %30, %13, %8
ret void
}

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