#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*/ addr;

/* Variables and functions */
int CHAR_BIT;
size_t SIZE_MAX;
size_t align_of(void *addr) {
  uintptr_t a = (uintptr_t)addr;
  int i;
  for (i = 0; i < sizeof(addr) * CHAR_BIT; i++) {
    if (a & ((1 << i) - 1))
      return i - 1;
  }
  return SIZE_MAX;
}


x86 assembly (clang, -O0):
<align_of>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    0x2ebe(%rip),%rcx
movslq (%rcx),%rcx
shl    $0x3,%rcx
cmp    %rcx,%rax
jae    1179 <align_of+0x79>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1166 <align_of+0x66>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %rax,-0x8(%rbp)
jmp    1187 <align_of+0x87>
jmp    116b <align_of+0x6b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <align_of+0x17>
mov    0x2e50(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<align_of>:
mov    0x2ed9(%rip),%rax
movslq (%rax),%rax
test   %rax,%rax
je     115d <align_of+0x5d>
shl    $0x3,%rax
cmp    $0x2,%rax
mov    $0x1,%edx
cmovae %rax,%rdx
movabs $0xffffffff00000000,%rax
ff ff ff
xor    %ecx,%ecx
movabs $0x100000000,%r8
cs nopw 0x0(%rax,%rax,1)
mov    $0xffffffff,%esi
shl    %cl,%esi
not    %esi
movslq %esi,%rsi
test   %rdi,%rsi
jne    1168 <align_of+0x68>
add    $0x1,%rcx
add    %r8,%rax
cmp    %rcx,%rdx
jne    1140 <align_of+0x40>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
ret
sar    $0x20,%rax
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@SIZE_MAX = global i64 0
define i64 @align_of(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = ptrtoint i8* %6 to i64
store i64 %7, i64* %4
store i32 0, i32* %5
br label %8
8: ; preds = %28, %1
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = load i32, i32* @CHAR_BIT
%12 = sext i32 %11 to i64
%13 = mul i64 8, %12
%14 = icmp ult i64 %10, %13
br i1 %14, label %15, label %31
15: ; preds = %8
%16 = load i64, i64* %4
%17 = load i32, i32* %5
%18 = shl i32 1, %17
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = and i64 %16, %20
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %15
%24 = load i32, i32* %5
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
store i64 %26, i64* %2
br label %33
27: ; preds = %15
br label %28
28: ; preds = %27
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %8
31: ; preds = %8
%32 = load i64, i64* @SIZE_MAX
store i64 %32, i64* %2
br label %33
33: ; preds = %31, %23
%34 = load i64, i64* %2
ret i64 %34
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@SIZE_MAX = global i64 0
define i64 @align_of(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = load i32, i32* @CHAR_BIT
%4 = icmp eq i32 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl nsw i64 %6, 3
%8 = call i64 @llvm.umax.i64(i64 %7, i64 1)
br label %9
9: ; preds = %5, %21
%10 = phi i64 [ 0, %5 ], [ %22, %21 ]
%11 = trunc i64 %10 to i32
%12 = shl nsw i32 -1, %11
%13 = xor i32 %12, -1
%14 = sext i32 %13 to i64
%15 = and i64 %14, %2
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %9
%18 = shl i64 %10, 32
%19 = add i64 %18, -4294967296
%20 = ashr exact i64 %19, 32
br label %26
21: ; preds = %9
%22 = add nuw i64 %10, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %24, label %9
24: ; preds = %21, %1
%25 = load i64, i64* @SIZE_MAX
br label %26
26: ; preds = %24, %17
%27 = phi i64 [ %20, %17 ], [ %25, %24 ]
ret i64 %27
}