#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 */
struct il_problem {
  int dummy;
};
typedef int /*<<< orphan*/ new_options;

/* Variables and functions */
size_t arc4random_uniform(int);
int /*<<< orphan*/ dpll(struct il_problem const *, unsigned char **,
                        int (*)(struct il_solution const *, void *), void *);
int /*<<< orphan*/ memcpy(unsigned char **, unsigned char const **, int);
scalar_t__ single_bit_set(unsigned char const);
bool guess(const struct il_problem *p, const unsigned char options[16][16],
           bool (*callback)(const struct il_solution *, void *), void *thunk) {
  size_t x, y;
  do {
    size_t u = arc4random_uniform(16 * 16);
    x = u / 16;
    y = u % 16;
  } while (single_bit_set(options[x][y]));
  for (unsigned char i = 0x1; i <= 0x8; i <<= 1) {
    if ((options[x][y] & i) != 0) {
      unsigned char new_options[16][16];
      memcpy(new_options, options, sizeof(new_options));
      new_options[x][y] = i;
      if (!dpll(p, new_options, callback, thunk))
        return false;
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<guess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x100,%edi
call   1030 <arc4random_uniform@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
shr    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x40(%rbp),%rax
and    $0xf,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <single_bit_set@plt>
cmp    $0x0,%rax
jne    115b <guess+0x1b>
movb   $0x1,-0x41(%rbp)
movzbl -0x41(%rbp),%eax
cmp    $0x8,%eax
jg     1255 <guess+0x115>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
movzbl -0x41(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1241 <guess+0x101>
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
mov    -0x41(%rbp),%dl
mov    -0x30(%rbp),%rcx
lea    -0x150(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    -0x38(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    -0x150(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <dpll@plt>
cmp    $0x0,%eax
jne    123c <guess+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    125c <guess+0x11c>
jmp    1241 <guess+0x101>
jmp    1246 <guess+0x106>
movzbl -0x41(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x41(%rbp)
jmp    11ab <guess+0x6b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r12
nop
mov    $0x100,%edi
call   1030 <arc4random_uniform@plt>
mov    %rax,%rbx
mov    %rax,%rbp
shr    $0x4,%rbp
and    $0xf,%ebx
shl    $0x4,%rbp
mov    %r13,%r14
add    %rbp,%r14
movzbl (%rbx,%r14,1),%edi
call   1060 <single_bit_set@plt>
test   %rax,%rax
jne    1160 <guess+0x20>
add    %rbx,%r14
add    %rsp,%rbp
add    $0x10,%rbp
or     %rbx,%rbp
mov    (%r14),%al
test   $0x1,%al
je     11db <guess+0x9b>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
movb   $0x1,0x0(%rbp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
call   1040 <dpll@plt>
test   %eax,%eax
je     1284 <guess+0x144>
mov    (%r14),%al
test   $0x2,%al
je     1212 <guess+0xd2>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
movb   $0x2,0x0(%rbp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
call   1040 <dpll@plt>
test   %eax,%eax
je     1284 <guess+0x144>
mov    (%r14),%al
test   $0x4,%al
je     1249 <guess+0x109>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
movb   $0x4,0x0(%rbp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
call   1040 <dpll@plt>
test   %eax,%eax
je     1284 <guess+0x144>
mov    (%r14),%al
test   $0x8,%al
je     127d <guess+0x13d>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
movb   $0x8,0x0(%rbp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    0x8(%rsp),%rcx
call   1040 <dpll@plt>
test   %eax,%eax
je     1284 <guess+0x144>
mov    $0x1,%eax
jmp    1286 <guess+0x146>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.il_problem = type { i32 }
%struct.il_solution = type opaque
%struct.il_solution.0 = type opaque
define i32 @guess(%struct.il_problem* %0, [16 x i8]* %1, i32 (%struct.il_solution*, i8*)* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.il_problem*
%7 = alloca [16 x i8]*
%8 = alloca i32 (%struct.il_solution*, i8*)*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i8
%14 = alloca [16 x [16 x i8]]
store %struct.il_problem* %0, %struct.il_problem** %6
store [16 x i8]* %1, [16 x i8]** %7
store i32 (%struct.il_solution*, i8*)* %2, i32 (%struct.il_solution*, i8*)** %8
store i8* %3, i8** %9
br label %15
15: ; preds = %21, %4
%16 = call i64 @arc4random_uniform(i32 256)
store i64 %16, i64* %12
%17 = load i64, i64* %12
%18 = udiv i64 %17, 16
store i64 %18, i64* %10
%19 = load i64, i64* %12
%20 = urem i64 %19, 16
store i64 %20, i64* %11
br label %21
21: ; preds = %15
%22 = load [16 x i8]*, [16 x i8]** %7
%23 = load i64, i64* %10
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %22, i64 %23
%25 = load i64, i64* %11
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %24, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = call i64 @single_bit_set(i8 zeroext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %15, label %30
30: ; preds = %21
store i8 1, i8* %13
br label %31
31: ; preds = %69, %30
%32 = load i8, i8* %13
%33 = zext i8 %32 to i32
%34 = icmp sle i32 %33, 8
br i1 %34, label %35, label %74
35: ; preds = %31
%36 = load [16 x i8]*, [16 x i8]** %7
%37 = load i64, i64* %10
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %36, i64 %37
%39 = load i64, i64* %11
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %38, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = load i8, i8* %13
%44 = zext i8 %43 to i32
%45 = and i32 %42, %44
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %68
47: ; preds = %35
%48 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %14, i64 0, i64 0
%49 = bitcast [16 x i8]* %48 to i8**
%50 = load [16 x i8]*, [16 x i8]** %7
%51 = bitcast [16 x i8]* %50 to i8**
%52 = call i32 @memcpy(i8** %49, i8** %51, i32 256)
%53 = load i8, i8* %13
%54 = load i64, i64* %10
%55 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %14, i64 0, i64 %54
%56 = load i64, i64* %11
%57 = getelementptr inbounds [16 x i8], [16 x i8]* %55, i64 0, i64 %56
store i8 %53, i8* %57
%58 = load %struct.il_problem*, %struct.il_problem** %6
%59 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %14, i64 0, i64 0
%60 = bitcast [16 x i8]* %59 to i8**
%61 = load i32 (%struct.il_solution*, i8*)*, i32 (%struct.il_solution*, i8*)** %8
%62 = bitcast i32 (%struct.il_solution*, i8*)* %61 to i32 (%struct.il_solution.0*, i8*)*
%63 = load i8*, i8** %9
%64 = call i32 @dpll(%struct.il_problem* %58, i8** %60, i32 (%struct.il_solution.0*, i8*)* %62, i8* %63)
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %47
store i32 0, i32* %5
br label %75
67: ; preds = %47
br label %68
68: ; preds = %67, %35
br label %69
69: ; preds = %68
%70 = load i8, i8* %13
%71 = zext i8 %70 to i32
%72 = shl i32 %71, 1
%73 = trunc i32 %72 to i8
store i8 %73, i8* %13
br label %31
74: ; preds = %31
store i32 1, i32* %5
br label %75
75: ; preds = %74, %66
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
%struct.il_problem = type { i32 }
%struct.il_solution = type opaque
%struct.il_solution.0 = type opaque
define i32 @guess(%struct.il_problem* %0, [16 x i8]* %1, i32 (%struct.il_solution*, i8*)* %2, i8* %3) {
%5 = alloca [16 x [16 x i8]]
br label %6
6: ; preds = %6, %4
%7 = tail call i64 @arc4random_uniform(i32 256)
%8 = lshr i64 %7, 4
%9 = and i64 %7, 15
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 %8, i64 %9
%11 = load i8, i8* %10
%12 = tail call i64 @single_bit_set(i8 zeroext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %6
14: ; preds = %6
%15 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %5, i64 0, i64 0, i64 0
%16 = bitcast [16 x [16 x i8]]* %5 to i8**
%17 = bitcast [16 x i8]* %1 to i8**
%18 = getelementptr inbounds [16 x [16 x i8]], [16 x [16 x i8]]* %5, i64 0, i64 %8, i64 %9
%19 = bitcast i32 (%struct.il_solution*, i8*)* %2 to i32 (%struct.il_solution.0*, i8*)*
%20 = load i8, i8* %10
%21 = and i8 %20, 1
%22 = icmp eq i8 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %14
%24 = call i32 @memcpy(i8** %16, i8** %17, i32 256)
store i8 1, i8* %18
%25 = call i32 @dpll(%struct.il_problem* %0, i8** %16, i32 (%struct.il_solution.0*, i8*)* %19, i8* %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %58, label %27
27: ; preds = %23
%28 = load i8, i8* %10
br label %29
29: ; preds = %27, %14
%30 = phi i8 [ %28, %27 ], [ %20, %14 ]
%31 = and i8 %30, 2
%32 = icmp eq i8 %31, 0
br i1 %32, label %39, label %33
33: ; preds = %29
%34 = call i32 @memcpy(i8** %16, i8** %17, i32 256)
store i8 2, i8* %18
%35 = call i32 @dpll(%struct.il_problem* %0, i8** %16, i32 (%struct.il_solution.0*, i8*)* %19, i8* %3)
%36 = icmp eq i32 %35, 0
br i1 %36, label %58, label %37
37: ; preds = %33
%38 = load i8, i8* %10
br label %39
39: ; preds = %37, %29
%40 = phi i8 [ %38, %37 ], [ %30, %29 ]
%41 = and i8 %40, 4
%42 = icmp eq i8 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %39
%44 = call i32 @memcpy(i8** %16, i8** %17, i32 256)
store i8 4, i8* %18
%45 = call i32 @dpll(%struct.il_problem* %0, i8** %16, i32 (%struct.il_solution.0*, i8*)* %19, i8* %3)
%46 = icmp eq i32 %45, 0
br i1 %46, label %58, label %47
47: ; preds = %43
%48 = load i8, i8* %10
br label %49
49: ; preds = %47, %39
%50 = phi i8 [ %48, %47 ], [ %40, %39 ]
%51 = and i8 %50, 8
%52 = icmp eq i8 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %49
%54 = call i32 @memcpy(i8** %16, i8** %17, i32 256)
store i8 8, i8* %18
%55 = call i32 @dpll(%struct.il_problem* %0, i8** %16, i32 (%struct.il_solution.0*, i8*)* %19, i8* %3)
%56 = icmp eq i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %53, %49
br label %58
58: ; preds = %57, %53, %43, %33, %23
%59 = phi i32 [ 0, %23 ], [ 0, %33 ], [ 0, %43 ], [ 0, %53 ], [ 1, %57 ]
ret i32 %59
}