#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 int atoi(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int parse_blocksize(const char *arg, unsigned int *out) {
  unsigned int target = atoi(arg);
  unsigned int c = 0;
  if (!target) {
    fprintf(stderr, "Block size must be greater than 0\n");
    return -1;
  }
  while (target > 1) {
    if (target & 1) {
      fprintf(stderr, "Block size must be a power of 2\n");
      return -1;
    }
    target >>= 1;
    c++;
  }
  *out = c;
  return 0;
}


x86 assembly (clang, -O0):
<parse_blocksize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116e <parse_blocksize+0x4e>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <parse_blocksize+0xb4>
jmp    1173 <parse_blocksize+0x53>
cmpl   $0x1,-0x1c(%rbp)
jbe    11c4 <parse_blocksize+0xa4>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11ad <parse_blocksize+0x8d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d4 <parse_blocksize+0xb4>
mov    -0x1c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1173 <parse_blocksize+0x53>
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_blocksize>:
push   %rbx
mov    %rsi,%rbx
call   1040 <atoi@plt>
test   %eax,%eax
je     1158 <parse_blocksize+0x38>
xor    %ecx,%ecx
cmp    $0x1,%eax
je     1152 <parse_blocksize+0x32>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
test   $0x1,%al
jne    116a <parse_blocksize+0x4a>
mov    %eax,%edx
shr    %edx
add    $0x1,%ecx
cmp    $0x3,%eax
mov    %edx,%eax
ja     1140 <parse_blocksize+0x20>
mov    %ecx,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
jmp    117a <parse_blocksize+0x5a>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xea9(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Block size must be greater than 0\0A\00"
@.str.1 = [33 x i8] c"Block size must be a power of 2\0A\00"
define i32 @parse_blocksize(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i32 @atoi(i8* %8)
store i32 %9, i32* %6
store i32 0, i32* %7
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
15: ; preds = %2
br label %16
16: ; preds = %26, %15
%17 = load i32, i32* %6
%18 = icmp ugt i32 %17, 1
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i32, i32* %6
%21 = and i32 %20, 1
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
26: ; preds = %19
%27 = load i32, i32* %6
%28 = lshr i32 %27, 1
store i32 %28, i32* %6
%29 = load i32, i32* %7
%30 = add i32 %29, 1
store i32 %30, i32* %7
br label %16
31: ; preds = %16
%32 = load i32, i32* %7
%33 = load i32*, i32** %5
store i32 %32, i32* %33
store i32 0, i32* %3
br label %34
34: ; preds = %31, %23, %12
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Block size must be greater than 0\0A\00"
@.str.1 = [33 x i8] c"Block size must be a power of 2\0A\00"
define i32 @parse_blocksize(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @atoi(i8* %0)
switch i32 %3, label %7 [
i32 0, label %4
i32 1, label %19
]
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %21
7: ; preds = %2, %15
%8 = phi i32 [ %17, %15 ], [ 0, %2 ]
%9 = phi i32 [ %16, %15 ], [ %3, %2 ]
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %21
15: ; preds = %7
%16 = lshr i32 %9, 1
%17 = add nuw nsw i32 %8, 1
%18 = icmp ugt i32 %9, 3
br i1 %18, label %7, label %19
19: ; preds = %15, %2
%20 = phi i32 [ 0, %2 ], [ %17, %15 ]
store i32 %20, i32* %1
br label %21
21: ; preds = %19, %12, %4
%22 = phi i32 [ -1, %12 ], [ 0, %19 ], [ -1, %4 ]
ret i32 %22
}