#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 *alloca(int);
int mlog(int x) {
  int *x_ref = alloca(sizeof(int));
  int *res = alloca(sizeof(int));
  *x_ref = x;
  *res = 0;
  while (*x_ref > 1) {
    *x_ref = (*x_ref) / 2;
    (*res)++;
  }
  return *res;
}


x86 assembly (clang, -O0):
<mlog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x1,(%rax)
jle    117d <mlog+0x6d>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    114a <mlog+0x3a>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mlog>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1030 <alloca@plt>
mov    %ebp,(%rbx)
movl   $0x0,(%rax)
mov    (%rbx),%edx
xor    %ecx,%ecx
cmp    $0x2,%edx
jl     1152 <mlog+0x42>
nopl   (%rax)
shr    %edx
mov    %edx,(%rbx)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    (%rbx),%edx
cmp    $0x1,%edx
jg     1140 <mlog+0x30>
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mlog(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
store i32 %0, i32* %2
%5 = call i32* @alloca(i32 4)
store i32* %5, i32** %3
%6 = call i32* @alloca(i32 4)
store i32* %6, i32** %4
%7 = load i32, i32* %2
%8 = load i32*, i32** %3
store i32 %7, i32* %8
%9 = load i32*, i32** %4
store i32 0, i32* %9
br label %10
10: ; preds = %14, %1
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = sdiv i32 %16, 2
%18 = load i32*, i32** %3
store i32 %17, i32* %18
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %19
br label %10
22: ; preds = %10
%23 = load i32*, i32** %4
%24 = load i32, i32* %23
ret i32 %24
}

LLVM IR (-O2):
define i32 @mlog(i32 %0) {
%2 = tail call i32* @alloca(i32 4)
%3 = tail call i32* @alloca(i32 4)
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %13
6: ; preds = %1, %6
%7 = phi i32 [ %11, %6 ], [ %4, %1 ]
%8 = lshr i32 %7, 1
store i32 %8, i32* %2
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 1
br i1 %12, label %6, label %13
13: ; preds = %6, %1
%14 = phi i32 [ 0, %1 ], [ %10, %6 ]
ret i32 %14
}