#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 */
int /*<<< orphan*/ ctr128_inc(unsigned char *);
void ctr128_inc_aligned(unsigned char *counter) {
  size_t *data, c, d, n;
  const union {
    long one;
    char little;
  } is_endian = {1};
  if (is_endian.little || ((size_t)counter % sizeof(size_t)) != 0) {
    ctr128_inc(counter);
    return;
  }
  data = (size_t *)counter;
  c = 1;
  n = 16 / sizeof(size_t);
  do {
    --n;
    d = data[n] += c;
    c = ((d - c) & ~d) >> (sizeof(size_t) * 8 - 1);
  } while (n);
}


x86 assembly (clang, -O0):
<ctr128_inc_aligned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x30(%rbp)
movsbl -0x30(%rbp),%eax
cmp    $0x0,%eax
jne    1146 <ctr128_inc_aligned+0x36>
mov    -0x8(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
je     1154 <ctr128_inc_aligned+0x44>
mov    -0x8(%rbp),%rdi
call   1030 <ctr128_inc@plt>
jmp    11b6 <ctr128_inc_aligned+0xa6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x1,-0x18(%rbp)
movq   $0x2,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
add    (%rcx,%rdx,8),%rax
mov    %rax,(%rcx,%rdx,8)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
xor    $0xffffffffffffffff,%rcx
and    %rcx,%rax
shr    $0x3f,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116c <ctr128_inc_aligned+0x5c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ctr128_inc_aligned>:
jmp    1030 <ctr128_inc@plt>

LLVM IR (-O0):
%union.anon = type { i64 }
@__const.ctr128_inc_aligned.is_endian = %union.anon { i64 1 }
define void @ctr128_inc_aligned(i8* %0) {
%2 = alloca i8*
%3 = alloca i64*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca %union.anon
store i8* %0, i8** %2
%8 = bitcast %union.anon* %7 to i8*
%9 = bitcast %union.anon* %7 to i8*
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = ptrtoint i8* %14 to i64
%16 = urem i64 %15, 8
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13, %1
%19 = load i8*, i8** %2
%20 = call i32 @ctr128_inc(i8* %19)
br label %43
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = bitcast i8* %22 to i64*
store i64* %23, i64** %3
store i64 1, i64* %4
store i64 2, i64* %6
br label %24
24: ; preds = %40, %21
%25 = load i64, i64* %6
%26 = add i64 %25, -1
store i64 %26, i64* %6
%27 = load i64, i64* %4
%28 = load i64*, i64** %3
%29 = load i64, i64* %6
%30 = getelementptr inbounds i64, i64* %28, i64 %29
%31 = load i64, i64* %30
%32 = add i64 %31, %27
store i64 %32, i64* %30
store i64 %32, i64* %5
%33 = load i64, i64* %5
%34 = load i64, i64* %4
%35 = sub i64 %33, %34
%36 = load i64, i64* %5
%37 = xor i64 %36, -1
%38 = and i64 %35, %37
%39 = lshr i64 %38, 63
store i64 %39, i64* %4
br label %40
40: ; preds = %24
%41 = load i64, i64* %6
%42 = icmp ne i64 %41, 0
br i1 %42, label %24, label %43
43: ; preds = %18, %40
ret void
}

LLVM IR (-O2):
define void @ctr128_inc_aligned(i8* %0) {
%2 = tail call i32 @ctr128_inc(i8* %0)
ret void
}