#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 unsigned long long uint64_t;

/* Variables and functions */
void f(uint64_t *a, uint64_t aa) {
  uint64_t new_value = aa;
  uint64_t old_value = *a;
  int bit_size = 32;
  uint64_t mask = (uint64_t)(unsigned)(-1);
  uint64_t tmp = old_value & mask;
  new_value &= mask;
  if (tmp > new_value)
    new_value += 1ull << bit_size;
  new_value += old_value & ~mask;
  *a = new_value;
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x20,-0x24(%rbp)
mov    $0xffffffff,%eax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
and    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    116a <f+0x6a>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
mov    (%rdi),%rax
mov    %eax,%ecx
mov    %esi,%edx
movabs $0x100000000,%rsi
or     %rdx,%rsi
cmp    %rdx,%rcx
cmovbe %rdx,%rsi
movabs $0xffffffff00000000,%rcx
ff ff ff
and    %rax,%rcx
add    %rsi,%rcx
mov    %rcx,(%rdi)
ret

LLVM IR (-O0):
define void @f(i64* %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
store i64* %0, i64** %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
store i64 %10, i64* %5
%11 = load i64*, i64** %3
%12 = load i64, i64* %11
store i64 %12, i64* %6
store i32 32, i32* %7
store i64 4294967295, i64* %8
%13 = load i64, i64* %6
%14 = load i64, i64* %8
%15 = and i64 %13, %14
store i64 %15, i64* %9
%16 = load i64, i64* %8
%17 = load i64, i64* %5
%18 = and i64 %17, %16
store i64 %18, i64* %5
%19 = load i64, i64* %9
%20 = load i64, i64* %5
%21 = icmp ugt i64 %19, %20
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32, i32* %7
%24 = zext i32 %23 to i64
%25 = shl i64 1, %24
%26 = load i64, i64* %5
%27 = add i64 %26, %25
store i64 %27, i64* %5
br label %28
28: ; preds = %22, %2
%29 = load i64, i64* %6
%30 = load i64, i64* %8
%31 = xor i64 %30, -1
%32 = and i64 %29, %31
%33 = load i64, i64* %5
%34 = add i64 %33, %32
store i64 %34, i64* %5
%35 = load i64, i64* %5
%36 = load i64*, i64** %3
store i64 %35, i64* %36
ret void
}

LLVM IR (-O2):
define void @f(i64* nocapture %0, i64 %1) {
%3 = load i64, i64* %0
%4 = and i64 %3, 4294967295
%5 = and i64 %1, 4294967295
%6 = icmp ugt i64 %4, %5
%7 = or i64 %5, 4294967296
%8 = select i1 %6, i64 %7, i64 %5
%9 = and i64 %3, -4294967296
%10 = add i64 %8, %9
store i64 %10, i64* %0
ret void
}