#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_modulo(long long unsigned a,
                                      long long unsigned b) {
  if (!b)
    return a;
  if (a == 0x8000000000000000 && b == 0xffffffffffffffff)
    return 0;
  return as_uint64(as_int64(a) % as_int64(b));
}


x86 assembly (clang, -O0):
<long_modulo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1148 <long_modulo+0x28>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119c <long_modulo+0x7c>
movabs $0x8000000000000000,%rax
cmp    %rax,-0x10(%rbp)
jne    1174 <long_modulo+0x54>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    1174 <long_modulo+0x54>
movq   $0x0,-0x8(%rbp)
jmp    119c <long_modulo+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    %edx,%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_modulo>:
push   %rbp
push   %rbx
push   %rax
test   %rsi,%rsi
je     1142 <long_modulo+0x22>
mov    %rsi,%rbx
movabs $0x8000000000000000,%rax
cmp    %rax,%rdi
jne    114c <long_modulo+0x2c>
cmp    $0xffffffffffffffff,%rbx
jne    114c <long_modulo+0x2c>
xor    %edi,%edi
mov    %rdi,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
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    %edx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <as_uint64@plt>

LLVM IR (-O0):
define i64 @long_modulo(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 %24
10: ; preds = %2
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, -9223372036854775808
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* %5
%15 = icmp eq i64 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %13
store i64 0, i64* %3
br label %24
17: ; preds = %13, %10
%18 = load i64, i64* %4
%19 = call i32 @as_int64(i64 %18)
%20 = load i64, i64* %5
%21 = call i32 @as_int64(i64 %20)
%22 = srem i32 %19, %21
%23 = call i64 @as_uint64(i32 %22)
store i64 %23, i64* %3
br label %24
24: ; preds = %17, %16, %8
%25 = load i64, i64* %3
ret i64 %25
}

LLVM IR (-O2):
define i64 @long_modulo(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 = srem 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 ], [ 0, %4 ]
ret i64 %14
}