#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 ERANGE;
int INT_MAX;
int INT_MIN;
int rf_div(int *z, int x, int y) {
  if (!y || (-INT_MAX != INT_MIN && x == INT_MIN && y == -1))
    return ERANGE;
  *z = x / y;
  return 0;
}


x86 assembly (clang, -O0):
<rf_div>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     114e <rf_div+0x4e>
xor    %eax,%eax
mov    0x2ec7(%rip),%rcx
sub    (%rcx),%eax
mov    0x2eb6(%rip),%rcx
cmp    (%rcx),%eax
je     115f <rf_div+0x5f>
mov    -0x14(%rbp),%eax
mov    0x2ea4(%rip),%rcx
cmp    (%rcx),%eax
jne    115f <rf_div+0x5f>
cmpl   $0xffffffff,-0x18(%rbp)
jne    115f <rf_div+0x5f>
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1175 <rf_div+0x75>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rf_div>:
test   %edx,%edx
je     112f <rf_div+0x2f>
mov    %edx,%ecx
mov    0x2edb(%rip),%rdx
mov    0x2ecc(%rip),%rax
mov    (%rax),%eax
mov    (%rdx),%edx
add    %eax,%edx
jne    1126 <rf_div+0x26>
mov    %esi,%eax
cltd
idiv   %ecx
mov    %eax,(%rdi)
xor    %eax,%eax
ret
cmp    $0xffffffff,%ecx
jne    111c <rf_div+0x1c>
cmp    %esi,%eax
jne    111c <rf_div+0x1c>
mov    0x2ea2(%rip),%rax
mov    (%rax),%eax
ret

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

LLVM IR (-O2):
@INT_MAX = global i32 0
@INT_MIN = global i32 0
@ERANGE = global i32 0
define i32 @rf_div(i32* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = load i32, i32* @INT_MAX
%7 = sub nsw i32 0, %6
%8 = load i32, i32* @INT_MIN
%9 = icmp eq i32 %8, %7
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = icmp eq i32 %8, %1
%12 = icmp eq i32 %2, -1
%13 = and i1 %12, %11
br i1 %13, label %14, label %16
14: ; preds = %10, %3
%15 = load i32, i32* @ERANGE
br label %18
16: ; preds = %10, %5
%17 = sdiv i32 %1, %2
store i32 %17, i32* %0
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ %15, %14 ], [ 0, %16 ]
ret i32 %19
}