#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_div(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_div>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1147 <builtin_div+0x27>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <push_from_long@plt>
jmp    11b1 <builtin_div+0x91>
cmpl   $0x1,-0xc(%rbp)
jne    1165 <builtin_div+0x45>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,%rdi
call   1040 <push_from_long@plt>
jmp    11b1 <builtin_div+0x91>
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     11a8 <builtin_div+0x88>
mov    $0x0,%al
call   1030 <pop_to_long@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1179 <builtin_div+0x59>
mov    -0x18(%rbp),%rdi
call   1040 <push_from_long@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<builtin_div>:
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     113b <builtin_div+0x1b>
mov    %esi,%ebx
xor    %eax,%eax
cmp    $0x1,%esi
jne    1140 <builtin_div+0x20>
call   1030 <pop_to_long@plt>
mov    %rax,%r14
jmp    1182 <builtin_div+0x62>
xor    %r14d,%r14d
jmp    1182 <builtin_div+0x62>
call   1030 <pop_to_long@plt>
mov    %rax,%r14
add    $0xffffffff,%ebx
jmp    1160 <builtin_div+0x40>
nopl   (%rax)
mov    %r14,%rax
cqto
idiv   %rcx
mov    %rax,%r14
add    $0xffffffff,%ebx
je     1182 <builtin_div+0x62>
xor    %eax,%eax
call   1030 <pop_to_long@plt>
mov    %rax,%rcx
or     %r14,%rax
shr    $0x20,%rax
jne    1150 <builtin_div+0x30>
mov    %r14d,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%r14d
add    $0xffffffff,%ebx
jne    1160 <builtin_div+0x40>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <push_from_long@plt>

LLVM IR (-O0):
%struct.Context = type { i32 }
define void @builtin_div(%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 = sdiv 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_div(%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 = sdiv i64 %10, %11
%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
}