#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 ffs(int);
int /*<<< orphan*/ printf(char *, char const *, int, int);
int _ffs(char const *progname) {
  int ret = 0;
  int i;
  int r;
  for (i = 0; i < 32; i++)
    if ((r = ffs(1 << i)) != i || (r = ffs(3 << i)) != i) {
      printf("%s: Obtained %d (expected: %d)\n", progname, r, i);
      ret = 2;
    }
  if ((r = ffs(0)) != 0) {
    printf("%s: Obtained %d (expected: %d)\n", progname, r, 0);
    ret = 3;
  }
  return ret;
}


x86 assembly (clang, -O0):
<_ffs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x20,-0x10(%rbp)
jge    11aa <_ffs+0x8a>
mov    -0x10(%rbp),%ecx
mov    $0x1,%edi
shl    %cl,%edi
call   1040 <ffs@plt>
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
jne    117a <_ffs+0x5a>
mov    -0x10(%rbp),%ecx
mov    $0x3,%edi
shl    %cl,%edi
call   1040 <ffs@plt>
mov    %eax,-0x14(%rbp)
cmp    -0x10(%rbp),%eax
je     1197 <_ffs+0x77>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe75(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0xc(%rbp)
jmp    119c <_ffs+0x7c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <_ffs+0x1a>
xor    %edi,%edi
call   1040 <ffs@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11d9 <_ffs+0xb9>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe35(%rip),%rdi
xor    %ecx,%ecx
call   1030 <printf@plt>
movl   $0x3,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_ffs>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %ecx,%ecx
lea    0xee0(%rip),%r14
lea    0x1(%rcx),%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <printf@plt>
mov    %ebp,%ecx
cmp    $0x20,%ebp
jne    1120 <_ffs+0x10>
mov    $0x2,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"%s: Obtained %d (expected: %d)\0A\00"
define i32 @_ffs(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %27, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 32
br i1 %8, label %9, label %30
9: ; preds = %6
%10 = load i32, i32* %4
%11 = shl i32 1, %10
%12 = call i32 @ffs(i32 %11)
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = shl i32 3, %16
%18 = call i32 @ffs(i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %15, %9
%22 = load i8*, i8** %2
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i32 %24)
store i32 2, i32* %3
br label %26
26: ; preds = %21, %15
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %6
30: ; preds = %6
%31 = call i32 @ffs(i32 0)
store i32 %31, i32* %5
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8*, i8** %2
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %34, i32 %35, i32 0)
store i32 3, i32* %3
br label %37
37: ; preds = %33, %30
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [32 x i8] c"%s: Obtained %d (expected: %d)\0A\00"
define i32 @_ffs(i8* %0) {
br label %2
2: ; preds = %1, %2
%3 = phi i32 [ 0, %1 ], [ %4, %2 ]
%4 = add nuw nsw i32 %3, 1
%5 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %4, i32 %3)
%6 = icmp eq i32 %4, 32
br i1 %6, label %7, label %2
7: ; preds = %2
ret i32 2
}