#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 */
unsigned long long l_mulu(unsigned long, unsigned long);
int /*<<< orphan*/ printf(char *);
unsigned long long int ll_mulu(unsigned long long int op1,
                               unsigned long long int op2) {
  unsigned long int a, b, c, d;
  unsigned long long int tmp, res;
  a = op1 >> 32;
  b = op1 & 0xffffffff;
  c = op2 >> 32;
  d = op2 & 0xffffffff;
  if ((a > 0) && (c > 0)) {
    printf("ll_mulu overflows\n");
  }
  tmp = l_mulu(a, d);
  if (tmp >= 0x100000000ULL) {
    printf("ll_mulu overflows\n");
  }
  res = tmp << 32;
  tmp = l_mulu(b, c);
  if (tmp >= 0x100000000ULL) {
    printf("ll_mulu overflows\n");
  }
  res += tmp << 32;
  tmp = res;
  res += l_mulu(b, d);
  if (res < tmp) {
    printf("ll_mulu overflows\n");
  }
  return res;
}


x86 assembly (clang, -O0):
<ll_mulu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shr    $0x20,%rax
mov    %rax,-0x18(%rbp)
movabs $0xffffffff,%rax
and    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x20,%rax
mov    %rax,-0x28(%rbp)
movabs $0xffffffff,%rax
and    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    118e <ll_mulu+0x6e>
cmpq   $0x0,-0x28(%rbp)
jbe    118e <ll_mulu+0x6e>
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <l_mulu@plt>
mov    %rax,-0x38(%rbp)
movabs $0x100000000,%rax
cmp    %rax,-0x38(%rbp)
jb     11bf <ll_mulu+0x9f>
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
shl    $0x20,%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <l_mulu@plt>
mov    %rax,-0x38(%rbp)
movabs $0x100000000,%rax
cmp    %rax,-0x38(%rbp)
jb     11fc <ll_mulu+0xdc>
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
shl    $0x20,%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <l_mulu@plt>
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    1243 <ll_mulu+0x123>
lea    0xdc2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ll_mulu>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %ebx,%r14d
shr    $0x20,%rbx
mov    %r12d,%r15d
shr    $0x20,%r12
test   %rbx,%rbx
je     1153 <ll_mulu+0x33>
test   %r12,%r12
je     1153 <ll_mulu+0x33>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <l_mulu@plt>
mov    %rax,%r13
shr    $0x20,%rax
je     1173 <ll_mulu+0x53>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <l_mulu@plt>
mov    %rax,%r12
shr    $0x20,%rax
je     1193 <ll_mulu+0x73>
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
add    %r12d,%r13d
shl    $0x20,%r13
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <l_mulu@plt>
mov    %rax,%rbx
add    %r13,%rbx
jae    11b9 <ll_mulu+0x99>
lea    0xe4c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"ll_mulu overflows\0A\00"
define i64 @ll_mulu(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%11 = load i64, i64* %3
%12 = lshr i64 %11, 32
store i64 %12, i64* %5
%13 = load i64, i64* %3
%14 = and i64 %13, 4294967295
store i64 %14, i64* %6
%15 = load i64, i64* %4
%16 = lshr i64 %15, 32
store i64 %16, i64* %7
%17 = load i64, i64* %4
%18 = and i64 %17, 4294967295
store i64 %18, i64* %8
%19 = load i64, i64* %5
%20 = icmp ugt i64 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i64, i64* %7
%23 = icmp ugt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21, %2
%27 = load i64, i64* %5
%28 = load i64, i64* %8
%29 = call i64 @l_mulu(i64 %27, i64 %28)
store i64 %29, i64* %9
%30 = load i64, i64* %9
%31 = icmp uge i64 %30, 4294967296
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %26
%35 = load i64, i64* %9
%36 = shl i64 %35, 32
store i64 %36, i64* %10
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = call i64 @l_mulu(i64 %37, i64 %38)
store i64 %39, i64* %9
%40 = load i64, i64* %9
%41 = icmp uge i64 %40, 4294967296
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %44
44: ; preds = %42, %34
%45 = load i64, i64* %9
%46 = shl i64 %45, 32
%47 = load i64, i64* %10
%48 = add i64 %47, %46
store i64 %48, i64* %10
%49 = load i64, i64* %10
store i64 %49, i64* %9
%50 = load i64, i64* %6
%51 = load i64, i64* %8
%52 = call i64 @l_mulu(i64 %50, i64 %51)
%53 = load i64, i64* %10
%54 = add i64 %53, %52
store i64 %54, i64* %10
%55 = load i64, i64* %10
%56 = load i64, i64* %9
%57 = icmp ult i64 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %44
%59 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %60
60: ; preds = %58, %44
%61 = load i64, i64* %10
ret i64 %61
}

LLVM IR (-O2):
@str.3 = [18 x i8] c"ll_mulu overflows\00"
define i64 @ll_mulu(i64 %0, i64 %1) {
%3 = lshr i64 %0, 32
%4 = and i64 %0, 4294967295
%5 = lshr i64 %1, 32
%6 = and i64 %1, 4294967295
%7 = icmp ugt i64 %0, 4294967295
%8 = icmp ugt i64 %1, 4294967295
%9 = and i1 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = tail call i64 @l_mulu(i64 %3, i64 %6)
%14 = icmp ugt i64 %13, 4294967295
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = tail call i64 @l_mulu(i64 %4, i64 %5)
%19 = icmp ugt i64 %18, 4294967295
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = add i64 %18, %13
%24 = shl i64 %23, 32
%25 = tail call i64 @l_mulu(i64 %4, i64 %6)
%26 = add i64 %25, %24
%27 = icmp ult i64 %26, %24
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
ret i64 %26
}