#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ rem;
  int quot;
};
typedef TYPE_1__ div_t;

/* Variables and functions */
TYPE_1__ div(int, int);
int INT_QUO(int a, int b) {
  div_t d = div(a, b);
  if (a < 0 && d.rem != 0) {
    d.quot += b < 0 ? 1 : -1;
  }
  return d.quot;
}


x86 assembly (clang, -O0):
<INT_QUO>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <div@plt>
mov    %rax,-0x18(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    115e <INT_QUO+0x4e>
cmpq   $0x0,-0x18(%rbp)
je     115e <INT_QUO+0x4e>
mov    -0x8(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<INT_QUO>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1030 <div@plt>
shr    $0x1f,%ebx
xor    %ecx,%ecx
test   %rax,%rax
lea    -0x1(%rbx,%rbx,1),%eax
cmove  %ecx,%eax
sar    $0x1f,%ebp
and    %eax,%ebp
add    %edx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i32 }
define i32 @INT_QUO(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.TYPE_3__
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = call { i64, i32 } @div(i32 %6, i32 %7)
%9 = bitcast %struct.TYPE_3__* %5 to { i64, i32 }*
%10 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 0
%11 = extractvalue { i64, i32 } %8, 0
store i64 %11, i64* %10
%12 = getelementptr inbounds { i64, i32 }, { i64, i32 }* %9, i32 0, i32 1
%13 = extractvalue { i64, i32 } %8, 1
store i32 %13, i32* %12
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %2
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%18 = load i64, i64* %17
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 1, i32 -1
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 1
%26 = load i32, i32* %25
%27 = add nsw i32 %26, %24
store i32 %27, i32* %25
br label %28
28: ; preds = %20, %16, %2
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 1
%30 = load i32, i32* %29
ret i32 %30
}

LLVM IR (-O2):
define i32 @INT_QUO(i32 %0, i32 %1) {
%3 = tail call { i64, i32 } @div(i32 %0, i32 %1)
%4 = extractvalue { i64, i32 } %3, 0
%5 = extractvalue { i64, i32 } %3, 1
%6 = icmp slt i32 %0, 0
%7 = icmp ne i64 %4, 0
%8 = select i1 %6, i1 %7, i1 false
%9 = icmp sgt i32 %1, -1
%10 = select i1 %9, i32 -1, i32 1
%11 = select i1 %8, i32 %10, i32 0
%12 = add nsw i32 %11, %5
ret i32 %12
}