#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 char rj_xtime(unsigned char);
unsigned char gf_log(unsigned char x) {
  unsigned char y, i = 0;
  if (x > 0)
    for (i = y = 1; i > 0; i++) {
      y ^= rj_xtime(y);
      if (y == x)
        break;
    }
  return i;
}


x86 assembly (clang, -O0):
<gf_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x3(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jle    1185 <gf_log+0x75>
movb   $0x1,-0x2(%rbp)
movb   $0x1,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jle    1180 <gf_log+0x70>
movzbl -0x2(%rbp),%edi
call   1030 <rj_xtime@plt>
movzbl %al,%ecx
movzbl -0x2(%rbp),%eax
xor    %ecx,%eax
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    116e <gf_log+0x5e>
jmp    1180 <gf_log+0x70>
jmp    1173 <gf_log+0x63>
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1137 <gf_log+0x27>
jmp    1185 <gf_log+0x75>
movzbl -0x3(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gf_log>:
push   %rbp
push   %r14
push   %rbx
test   %edi,%edi
je     1137 <gf_log+0x27>
mov    %edi,%r14d
mov    $0x1,%bl
mov    $0x1,%bpl
movzbl %bpl,%ebp
mov    %ebp,%edi
call   1030 <rj_xtime@plt>
xor    %al,%bpl
cmp    %r14b,%bpl
je     1139 <gf_log+0x29>
inc    %bl
jne    1120 <gf_log+0x10>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @gf_log(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
store i8 0, i8* %4
%5 = load i8, i8* %2
%6 = zext i8 %5 to i32
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %32
8: ; preds = %1
store i8 1, i8* %3
store i8 1, i8* %4
br label %9
9: ; preds = %28, %8
%10 = load i8, i8* %4
%11 = zext i8 %10 to i32
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i8, i8* %3
%15 = call zeroext i8 @rj_xtime(i8 zeroext %14)
%16 = zext i8 %15 to i32
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = xor i32 %18, %16
%20 = trunc i32 %19 to i8
store i8 %20, i8* %3
%21 = load i8, i8* %3
%22 = zext i8 %21 to i32
%23 = load i8, i8* %2
%24 = zext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %13
br label %31
27: ; preds = %13
br label %28
28: ; preds = %27
%29 = load i8, i8* %4
%30 = add i8 %29, 1
store i8 %30, i8* %4
br label %9
31: ; preds = %26, %9
br label %32
32: ; preds = %31, %1
%33 = load i8, i8* %4
ret i8 %33
}

LLVM IR (-O2):
define zeroext i8 @gf_log(i8 zeroext %0) {
%2 = icmp eq i8 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1, %9
%4 = phi i8 [ %10, %9 ], [ 1, %1 ]
%5 = phi i8 [ %7, %9 ], [ 1, %1 ]
%6 = tail call zeroext i8 @rj_xtime(i8 zeroext %5)
%7 = xor i8 %6, %5
%8 = icmp eq i8 %7, %0
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = add i8 %4, 1
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %3
12: ; preds = %9, %3, %1
%13 = phi i8 [ 0, %1 ], [ 0, %9 ], [ %4, %3 ]
ret i8 %13
}