#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 */

/* Variables and functions */
int as_int64(unsigned long long);
unsigned long long as_uint64(int);
extern long long unsigned long_divide(long long unsigned a,
                                      long long unsigned b) {
  if (!b)
    return a;
  if (a == 0x8000000000000000 && b == 0xffffffffffffffff)
    return a;
  return as_uint64(as_int64(a) / as_int64(b));
}


x86 assembly (clang, -O0):
<long_divide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1148 <long_divide+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <long_divide+0x7c>
movabs $0x8000000000000000,%rax
cmp    %rax,-0x10(%rbp)
jne    1174 <long_divide+0x54>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1174 <long_divide+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <long_divide+0x7c>
mov    -0x10(%rbp),%rdi
call   1030 <as_int64@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <as_int64@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <as_uint64@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<long_divide>:
push   %rbp
push   %rbx
push   %rax
test   %rsi,%rsi
je     1163 <long_divide+0x43>
mov    %rsi,%rbx
movabs $0x8000000000000000,%rax
cmp    %rax,%rdi
jne    1140 <long_divide+0x20>
cmp    $0xffffffffffffffff,%rbx
je     1166 <long_divide+0x46>
call   1030 <as_int64@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <as_int64@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <as_uint64@plt>
mov    %rdi,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @long_divide(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %5
%7 = icmp ne i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = load i64, i64* %4
store i64 %9, i64* %3
br label %25
10: ; preds = %2
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, -9223372036854775808
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i64, i64* %5
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = load i64, i64* %4
store i64 %17, i64* %3
br label %25
18: ; preds = %13, %10
%19 = load i64, i64* %4
%20 = call i32 @as_int64(i64 %19)
%21 = load i64, i64* %5
%22 = call i32 @as_int64(i64 %21)
%23 = sdiv i32 %20, %22
%24 = call i64 @as_uint64(i32 %23)
store i64 %24, i64* %3
br label %25
25: ; preds = %18, %16, %8
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
define i64 @long_divide(i64 %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = icmp eq i64 %0, -9223372036854775808
%6 = icmp eq i64 %1, -1
%7 = and i1 %5, %6
br i1 %7, label %13, label %8
8: ; preds = %4
%9 = tail call i32 @as_int64(i64 %0)
%10 = tail call i32 @as_int64(i64 %1)
%11 = sdiv i32 %9, %10
%12 = tail call i64 @as_uint64(i32 %11)
br label %13
13: ; preds = %4, %2, %8
%14 = phi i64 [ %12, %8 ], [ %0, %2 ], [ -9223372036854775808, %4 ]
ret i64 %14
}