#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*/ ulong;
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ ULONG_MAX;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gmp_fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
scalar_t__ mpz_cmp_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_get_ui(int /*<<< orphan*/);
scalar_t__ mpz_sgn(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
extern ulong mpz_strict_get_ui(mpz_t z) {
  if (mpz_sgn(z) < 0 || mpz_cmp_ui(z, ULONG_MAX) > 0) {
    gmp_fprintf(stderr, "strict ulong overflow converting %Zd\n", z);
    exit(1);
  }
  return mpz_get_ui(z);
}


x86 assembly (clang, -O0):
<mpz_strict_get_ui>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <mpz_sgn@plt>
cmp    $0x0,%rax
jl     1188 <mpz_strict_get_ui+0x38>
mov    -0x4(%rbp),%edi
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
call   1040 <mpz_cmp_ui@plt>
cmp    $0x0,%rax
jle    11aa <mpz_strict_get_ui+0x5a>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe65(%rip),%rsi
call   1060 <gmp_fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <mpz_get_ui@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpz_strict_get_ui>:
push   %rbx
mov    %edi,%ebx
call   1070 <mpz_sgn@plt>
test   %rax,%rax
js     117a <mpz_strict_get_ui+0x2a>
mov    0x2e6c(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <mpz_cmp_ui@plt>
test   %rax,%rax
jg     117a <mpz_strict_get_ui+0x2a>
mov    %ebx,%edi
pop    %rbx
jmp    1030 <mpz_get_ui@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
mov    %ebx,%edx
call   1060 <gmp_fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@ULONG_MAX = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"strict ulong overflow converting %Zd\0A\00"
define i32 @mpz_strict_get_ui(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i64 @mpz_sgn(i32 %3)
%5 = icmp slt i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = load i32, i32* @ULONG_MAX
%9 = call i64 @mpz_cmp_ui(i32 %7, i32 %8)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6, %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* %2
%14 = call i32 @gmp_fprintf(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %6
%17 = load i32, i32* %2
%18 = call i32 @mpz_get_ui(i32 %17)
ret i32 %18
}

LLVM IR (-O2):
@ULONG_MAX = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"strict ulong overflow converting %Zd\0A\00"
define i32 @mpz_strict_get_ui(i32 %0) {
%2 = tail call i64 @mpz_sgn(i32 %0)
%3 = icmp slt i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @ULONG_MAX
%6 = tail call i64 @mpz_cmp_ui(i32 %0, i32 %5)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4, %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @gmp_fprintf(i32 %9, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %4
%13 = tail call i32 @mpz_get_ui(i32 %0)
ret i32 %13
}