#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*/ uintmax_t;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int CHAR_BIT;
int UINTMAX_MAX;
int /*<<< orphan*/ die(char *, int /*<<< orphan*/, int /*<<< orphan*/);
size_t st_add(size_t a, size_t b) {
  if (((b) > (UINTMAX_MAX >>
              ((CHAR_BIT * sizeof(uintmax_t)) - (CHAR_BIT * sizeof(a)))) -
                 (a)))
    die("size_t overflow: %llu + %llu", (uintmax_t)a, (uintmax_t)b);
  return a + b;
}


x86 assembly (clang, -O0):
<st_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ec5(%rip),%rcx
mov    (%rcx),%edx
mov    0x2ea4(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x2,%rcx
mov    0x2e96(%rip),%rsi
movslq (%rsi),%rsi
shl    $0x3,%rsi
sub    %rsi,%rcx
sar    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
sub    -0x8(%rbp),%rcx
cmp    %rcx,%rax
jbe    1178 <st_add+0x68>
mov    -0x8(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0xe8d(%rip),%rdi
call   1030 <die@plt>
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<st_add>:
push   %r14
push   %rbx
push   %rax
mov    0x2ed5(%rip),%rax
mov    (%rax),%eax
mov    0x2eb4(%rip),%rcx
mov    (%rcx),%cl
shl    $0x2,%cl
neg    %cl
sar    %cl,%eax
mov    %rsi,%rbx
mov    %rdi,%r14
cltq
sub    %rdi,%rax
cmp    %rsi,%rax
jae    114e <st_add+0x3e>
lea    0xebc(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
call   1030 <die@plt>
add    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@UINTMAX_MAX = global i32 0
@CHAR_BIT = global i32 0
@.str = [29 x i8] c"size_t overflow: %llu + %llu\00"
define i64 @st_add(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%5 = load i64, i64* %4
%6 = load i32, i32* @UINTMAX_MAX
%7 = load i32, i32* @CHAR_BIT
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = load i32, i32* @CHAR_BIT
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 8
%13 = sub i64 %9, %12
%14 = trunc i64 %13 to i32
%15 = ashr i32 %6, %14
%16 = sext i32 %15 to i64
%17 = load i64, i64* %3
%18 = sub i64 %16, %17
%19 = icmp ugt i64 %5, %18
br i1 %19, label %20, label %26
20: ; preds = %2
%21 = load i64, i64* %3
%22 = trunc i64 %21 to i32
%23 = load i64, i64* %4
%24 = trunc i64 %23 to i32
%25 = call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %24)
br label %26
26: ; preds = %20, %2
%27 = load i64, i64* %3
%28 = load i64, i64* %4
%29 = add i64 %27, %28
ret i64 %29
}

LLVM IR (-O2):
@UINTMAX_MAX = global i32 0
@CHAR_BIT = global i32 0
@.str = [29 x i8] c"size_t overflow: %llu + %llu\00"
define i64 @st_add(i64 %0, i64 %1) {
%3 = load i32, i32* @UINTMAX_MAX
%4 = load i32, i32* @CHAR_BIT
%5 = mul i32 %4, -4
%6 = ashr i32 %3, %5
%7 = sext i32 %6 to i64
%8 = sub i64 %7, %0
%9 = icmp ult i64 %8, %1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = trunc i64 %0 to i32
%12 = trunc i64 %1 to i32
%13 = tail call i32 @die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
br label %14
14: ; preds = %10, %2
%15 = add i64 %1, %0
ret i64 %15
}