#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ __udivmoddi4(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
int64_t __divdi3(int64_t num, int64_t den) {
  int minus = 0;
  int64_t v;
  if (num < 0) {
    num = -num;
    minus = 1;
  }
  if (den < 0) {
    den = -den;
    minus ^= 1;
  }
  v = __udivmoddi4(num, den, NULL);
  if (minus)
    v = -v;
  return v;
}


x86 assembly (clang, -O0):
<__divdi3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    113e <__divdi3+0x2e>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1159 <__divdi3+0x49>
xor    %eax,%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
xor    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <__udivmoddi4@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117d <__divdi3+0x6d>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__divdi3>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
neg    %edi
cmovs  %ebx,%edi
mov    %esi,%ebp
neg    %esi
cmovs  %ebp,%esi
xor    %edx,%edx
call   1030 <__udivmoddi4@plt>
mov    %eax,%ecx
neg    %ecx
xor    %ebx,%ebp
cmovs  %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__divdi3(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* %3
%11 = sub nsw i32 0, %10
store i32 %11, i32* %3
store i32 1, i32* %5
br label %12
12: ; preds = %9, %2
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i32, i32* %4
%17 = sub nsw i32 0, %16
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = xor i32 %18, 1
store i32 %19, i32* %5
br label %20
20: ; preds = %15, %12
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = call i32 @__udivmoddi4(i32 %21, i32 %22, i32* null)
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i32, i32* %6
%28 = sub nsw i32 0, %27
store i32 %28, i32* %6
br label %29
29: ; preds = %26, %20
%30 = load i32, i32* %6
ret i32 %30
}

LLVM IR (-O2):
define i32 @__divdi3(i32 %0, i32 %1) {
%3 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%4 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
%5 = xor i32 %1, %0
%6 = tail call i32 @__udivmoddi4(i32 %3, i32 %4, i32* null)
%7 = icmp sgt i32 %5, -1
%8 = sub nsw i32 0, %6
%9 = select i1 %7, i32 %6, i32 %8
ret i32 %9
}