#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 */
bool ST64_MUL_OVFCHK(long long a, long long b) {
  if (a > 0) {
    if (b > 0) {
      return a > ((long long)0x7FFFFFFFFFFFFFFFULL) / b;
    }
    return b < ((long long)(-((long long)0x7FFFFFFFFFFFFFFFULL) - 1)) / a;
  }
  if (b > 0) {
    return a < ((long long)(-((long long)0x7FFFFFFFFFFFFFFFULL) - 1)) / b;
  }
  return a && b < ((long long)0x7FFFFFFFFFFFFFFFULL) / a;
}


x86 assembly (clang, -O0):
<ST64_MUL_OVFCHK>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1186 <ST64_MUL_OVFCHK+0x86>
cmpq   $0x0,-0x18(%rbp)
jle    1154 <ST64_MUL_OVFCHK+0x54>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movabs $0x7fffffffffffffff,%rax
ff ff 7f
cqto
idivq  -0x18(%rbp)
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <ST64_MUL_OVFCHK+0x106>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movabs $0x8000000000000000,%rax
cqto
idivq  -0x10(%rbp)
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <ST64_MUL_OVFCHK+0x106>
cmpq   $0x0,-0x18(%rbp)
jle    11c3 <ST64_MUL_OVFCHK+0xc3>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movabs $0x8000000000000000,%rax
cqto
idivq  -0x18(%rbp)
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    1206 <ST64_MUL_OVFCHK+0x106>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x31(%rbp)
je     11fb <ST64_MUL_OVFCHK+0xfb>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
movabs $0x7fffffffffffffff,%rax
ff ff 7f
cqto
idivq  -0x10(%rbp)
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
cmp    %rcx,%rax
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ST64_MUL_OVFCHK>:
test   %rdi,%rdi
jle    1123 <ST64_MUL_OVFCHK+0x23>
test   %rsi,%rsi
jle    113f <ST64_MUL_OVFCHK+0x3f>
movabs $0x7fffffffffffffff,%rax
ff ff 7f
xor    %edx,%edx
div    %rsi
cmp    %rdi,%rax
setb   %al
movzbl %al,%eax
ret
test   %rsi,%rsi
jle    114b <ST64_MUL_OVFCHK+0x4b>
movabs $0x8000000000000000,%rax
xor    %edx,%edx
div    %rsi
neg    %rax
cmp    %rdi,%rax
jmp    1168 <ST64_MUL_OVFCHK+0x68>
movabs $0x8000000000000000,%rax
jmp    115d <ST64_MUL_OVFCHK+0x5d>
test   %rdi,%rdi
je     116f <ST64_MUL_OVFCHK+0x6f>
neg    %rdi
movabs $0x7fffffffffffffff,%rax
ff ff 7f
xor    %edx,%edx
div    %rdi
neg    %rax
cmp    %rsi,%rax
setg   %al
movzbl %al,%eax
ret
xor    %eax,%eax
movzbl %al,%eax
ret

LLVM IR (-O0):
define i32 @ST64_MUL_OVFCHK(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %2
%9 = load i64, i64* %5
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i64, i64* %4
%13 = load i64, i64* %5
%14 = sdiv i64 9223372036854775807, %13
%15 = icmp sgt i64 %12, %14
%16 = zext i1 %15 to i32
store i32 %16, i32* %3
br label %43
17: ; preds = %8
%18 = load i64, i64* %5
%19 = load i64, i64* %4
%20 = sdiv i64 -9223372036854775808, %19
%21 = icmp slt i64 %18, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %3
br label %43
23: ; preds = %2
%24 = load i64, i64* %5
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i64, i64* %4
%28 = load i64, i64* %5
%29 = sdiv i64 -9223372036854775808, %28
%30 = icmp slt i64 %27, %29
%31 = zext i1 %30 to i32
store i32 %31, i32* %3
br label %43
32: ; preds = %23
%33 = load i64, i64* %4
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i64, i64* %5
%37 = load i64, i64* %4
%38 = sdiv i64 9223372036854775807, %37
%39 = icmp slt i64 %36, %38
br label %40
40: ; preds = %35, %32
%41 = phi i1 [ false, %32 ], [ %39, %35 ]
%42 = zext i1 %41 to i32
store i32 %42, i32* %3
br label %43
43: ; preds = %40, %26, %17, %11
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @ST64_MUL_OVFCHK(i64 %0, i64 %1) {
%3 = icmp sgt i64 %0, 0
%4 = icmp sgt i64 %1, 0
br i1 %3, label %5, label %13
5: ; preds = %2
br i1 %4, label %6, label %9
6: ; preds = %5
%7 = udiv i64 9223372036854775807, %1
%8 = icmp ult i64 %7, %0
br label %25
9: ; preds = %5
%10 = udiv i64 -9223372036854775808, %0
%11 = sub i64 0, %10
%12 = icmp sgt i64 %11, %1
br label %25
13: ; preds = %2
br i1 %4, label %14, label %18
14: ; preds = %13
%15 = udiv i64 -9223372036854775808, %1
%16 = sub i64 0, %15
%17 = icmp sgt i64 %16, %0
br label %25
18: ; preds = %13
%19 = icmp eq i64 %0, 0
br i1 %19, label %25, label %20
20: ; preds = %18
%21 = sub i64 0, %0
%22 = udiv i64 9223372036854775807, %21
%23 = sub nsw i64 0, %22
%24 = icmp sgt i64 %23, %1
br label %25
25: ; preds = %18, %20, %14, %9, %6
%26 = phi i1 [ %8, %6 ], [ %12, %9 ], [ %17, %14 ], [ false, %18 ], [ %24, %20 ]
%27 = zext i1 %26 to i32
ret i32 %27
}