#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ init_matrix();
int /*<<< orphan*/ insert_random_value_in_cell(int);
int /*<<< orphan*/ insert_value_in_cell(int, int, int, int);
void generate_sudoku_matrix(unsigned solved_cells, unsigned visible_cells) {
  unsigned i, cells_left = solved_cells - visible_cells;
  assert(solved_cells >= visible_cells);
  init_matrix();
  insert_value_in_cell(1, 1, 9, true);
  for (i = 0; i < visible_cells; i++) {
    insert_random_value_in_cell(true);
  }
  for (i = 0; i < cells_left; i++) {
    insert_random_value_in_cell(false);
  }
}


x86 assembly (clang, -O0):
<generate_sudoku_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1060 <init_matrix@plt>
mov    $0x1,%ecx
mov    $0x9,%edx
mov    %ecx,%edi
mov    %ecx,%esi
call   1040 <insert_value_in_cell@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11af <generate_sudoku_matrix+0x6f>
mov    $0x1,%edi
call   1030 <insert_random_value_in_cell@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <generate_sudoku_matrix+0x4b>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    11d7 <generate_sudoku_matrix+0x97>
xor    %edi,%edi
call   1030 <insert_random_value_in_cell@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b6 <generate_sudoku_matrix+0x76>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_sudoku_matrix>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %edi,%edi
sub    %esi,%ebx
setae  %dil
call   1050 <assert@plt>
xor    %eax,%eax
call   1060 <init_matrix@plt>
mov    $0x1,%edi
mov    $0x1,%esi
mov    $0x9,%edx
mov    $0x1,%ecx
call   1040 <insert_value_in_cell@plt>
test   %ebp,%ebp
je     118f <generate_sudoku_matrix+0x4f>
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1030 <insert_random_value_in_cell@plt>
add    $0xffffffff,%ebp
jne    1180 <generate_sudoku_matrix+0x40>
test   %ebx,%ebx
je     11ac <generate_sudoku_matrix+0x6c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
call   1030 <insert_random_value_in_cell@plt>
add    $0xffffffff,%ebx
jne    11a0 <generate_sudoku_matrix+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @generate_sudoku_matrix(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = load i32, i32* %4
%9 = sub i32 %7, %8
store i32 %9, i32* %6
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = icmp uge i32 %10, %11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = call i32 (...) @init_matrix()
%16 = call i32 @insert_value_in_cell(i32 1, i32 1, i32 9, i32 1)
store i32 0, i32* %5
br label %17
17: ; preds = %23, %2
%18 = load i32, i32* %5
%19 = load i32, i32* %4
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = call i32 @insert_random_value_in_cell(i32 1)
br label %23
23: ; preds = %21
%24 = load i32, i32* %5
%25 = add i32 %24, 1
store i32 %25, i32* %5
br label %17
26: ; preds = %17
store i32 0, i32* %5
br label %27
27: ; preds = %33, %26
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %36
31: ; preds = %27
%32 = call i32 @insert_random_value_in_cell(i32 0)
br label %33
33: ; preds = %31
%34 = load i32, i32* %5
%35 = add i32 %34, 1
store i32 %35, i32* %5
br label %27
36: ; preds = %27
ret void
}

LLVM IR (-O2):
define void @generate_sudoku_matrix(i32 %0, i32 %1) {
%3 = sub i32 %0, %1
%4 = icmp uge i32 %0, %1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = tail call i32 (...) @init_matrix()
%8 = tail call i32 @insert_value_in_cell(i32 1, i32 1, i32 9, i32 1)
%9 = icmp eq i32 %1, 0
br i1 %9, label %10, label %12
10: ; preds = %12, %2
%11 = icmp eq i32 %3, 0
br i1 %11, label %22, label %17
12: ; preds = %2, %12
%13 = phi i32 [ %15, %12 ], [ 0, %2 ]
%14 = tail call i32 @insert_random_value_in_cell(i32 1)
%15 = add nuw i32 %13, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %10, label %12
17: ; preds = %10, %17
%18 = phi i32 [ %20, %17 ], [ 0, %10 ]
%19 = tail call i32 @insert_random_value_in_cell(i32 0)
%20 = add nuw i32 %18, 1
%21 = icmp eq i32 %20, %3
br i1 %21, label %22, label %17
22: ; preds = %17, %10
ret void
}