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

/* Variables and functions */
int /*<<< orphan*/ __udivmodsi4(int /*<<< orphan*/, int /*<<< orphan*/,
                                int /*<<< orphan*/ *);
int32_t __modsi3(int32_t num, int32_t den) {
  int minus = 0;
  int32_t v;
  if (num < 0) {
    num = -num;
    minus = 1;
  }
  if (den < 0) {
    den = -den;
    minus ^= 1;
  }
  (void)__udivmodsi4(num, den, (uint32_t *)&v);
  if (minus)
    v = -v;
  return v;
}


x86 assembly (clang, -O0):
<__modsi3>:
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 <__modsi3+0x2e>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1159 <__modsi3+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
lea    -0x10(%rbp),%rdx
call   1030 <__udivmodsi4@plt>
cmpl   $0x0,-0xc(%rbp)
je     117a <__modsi3+0x6a>
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):
<__modsi3>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
neg    %edi
cmovs  %ebx,%edi
mov    %esi,%ebp
neg    %esi
cmovs  %ebp,%esi
lea    0x4(%rsp),%rdx
call   1030 <__udivmodsi4@plt>
mov    0x4(%rsp),%ecx
mov    %ecx,%eax
neg    %eax
xor    %ebx,%ebp
cmovns %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @__modsi3(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 @__udivmodsi4(i32 %21, i32 %22, 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 @__modsi3(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @llvm.abs.i32(i32 %0, i1 true)
%6 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
%7 = xor i32 %1, %0
%8 = call i32 @__udivmodsi4(i32 %5, i32 %6, i32* %3)
%9 = icmp sgt i32 %7, -1
%10 = load i32, i32* %3
%11 = sub nsw i32 0, %10
%12 = select i1 %9, i32 %10, i32 %11
ret i32 %12
}