#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 count_key_block(int **, int, int, int);
int count_key_column(int **, int, int);
int count_key_line(int **, int, int);
bool check_grid(int sudoku[9][9]) {
  int k;
  int position;
  int v;
  int h;
  position = 81;
  while (position--) {
    v = position / 9;
    h = position % 9;
    k = 0;
    if (sudoku[v][h] > 9)
      return false;
    while (k++ < 9) {
      if (count_key_line(sudoku, v, k) > 1)
        return false;
      if (count_key_column(sudoku, h, k) > 1)
        return false;
      if (count_key_block(sudoku, v, h, k) > 1)
        return false;
    }
  }
  return true;
}


x86 assembly (clang, -O0):
<check_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x51,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1235 <check_grid+0x105>
mov    -0x18(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
imul   $0x24,%rcx,%rcx
add    %rcx,%rax
movslq -0x20(%rbp),%rcx
cmpl   $0x9,(%rax,%rcx,4)
jle    11a3 <check_grid+0x73>
movl   $0x0,-0x4(%rbp)
jmp    123c <check_grid+0x10c>
jmp    11a8 <check_grid+0x78>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x9,%eax
jge    1230 <check_grid+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <count_key_line@plt>
cmp    $0x1,%eax
jle    11e0 <check_grid+0xb0>
movl   $0x0,-0x4(%rbp)
jmp    123c <check_grid+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1050 <count_key_column@plt>
cmp    $0x1,%eax
jle    1204 <check_grid+0xd4>
movl   $0x0,-0x4(%rbp)
jmp    123c <check_grid+0x10c>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <count_key_block@plt>
cmp    $0x1,%eax
jle    122b <check_grid+0xfb>
movl   $0x0,-0x4(%rbp)
jmp    123c <check_grid+0x10c>
jmp    11a8 <check_grid+0x78>
jmp    1143 <check_grid+0x13>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_grid>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    $0x50,%r13d
xor    %r14d,%r14d
mov    %r13d,%eax
imul   $0x38e38e39,%rax,%r12
shr    $0x21,%r12
lea    (%r12,%r12,8),%eax
mov    %r13d,%ebx
sub    %eax,%ebx
lea    (%r12,%r12,8),%rax
lea    (%r15,%rax,4),%rax
cmpl   $0x9,(%rax,%rbx,4)
jg     11e0 <check_grid+0xb0>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%ebp
je     11d0 <check_grid+0xa0>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1040 <count_key_line@plt>
cmp    $0x1,%eax
jg     11e0 <check_grid+0xb0>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1050 <count_key_column@plt>
cmp    $0x1,%eax
jg     11e0 <check_grid+0xb0>
mov    %r15,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1030 <count_key_block@plt>
add    $0x1,%ebp
cmp    $0x2,%eax
jl     1180 <check_grid+0x50>
jmp    11e0 <check_grid+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
sub    $0x1,%r13d
jae    1147 <check_grid+0x17>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @check_grid([9 x i32]* %0) {
%2 = alloca i32
%3 = alloca [9 x i32]*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store [9 x i32]* %0, [9 x i32]** %3
store i32 81, i32* %5
br label %8
8: ; preds = %58, %1
%9 = load i32, i32* %5
%10 = add nsw i32 %9, -1
store i32 %10, i32* %5
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %59
12: ; preds = %8
%13 = load i32, i32* %5
%14 = sdiv i32 %13, 9
store i32 %14, i32* %6
%15 = load i32, i32* %5
%16 = srem i32 %15, 9
store i32 %16, i32* %7
store i32 0, i32* %4
%17 = load [9 x i32]*, [9 x i32]** %3
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [9 x i32], [9 x i32]* %17, i64 %19
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [9 x i32], [9 x i32]* %20, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = icmp sgt i32 %24, 9
br i1 %25, label %26, label %27
26: ; preds = %12
store i32 0, i32* %2
br label %60
27: ; preds = %12
br label %28
28: ; preds = %57, %27
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
%31 = icmp slt i32 %29, 9
br i1 %31, label %32, label %58
32: ; preds = %28
%33 = load [9 x i32]*, [9 x i32]** %3
%34 = bitcast [9 x i32]* %33 to i32**
%35 = load i32, i32* %6
%36 = load i32, i32* %4
%37 = call i32 @count_key_line(i32** %34, i32 %35, i32 %36)
%38 = icmp sgt i32 %37, 1
br i1 %38, label %39, label %40
39: ; preds = %32
store i32 0, i32* %2
br label %60
40: ; preds = %32
%41 = load [9 x i32]*, [9 x i32]** %3
%42 = bitcast [9 x i32]* %41 to i32**
%43 = load i32, i32* %7
%44 = load i32, i32* %4
%45 = call i32 @count_key_column(i32** %42, i32 %43, i32 %44)
%46 = icmp sgt i32 %45, 1
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 0, i32* %2
br label %60
48: ; preds = %40
%49 = load [9 x i32]*, [9 x i32]** %3
%50 = bitcast [9 x i32]* %49 to i32**
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = load i32, i32* %4
%54 = call i32 @count_key_block(i32** %50, i32 %51, i32 %52, i32 %53)
%55 = icmp sgt i32 %54, 1
br i1 %55, label %56, label %57
56: ; preds = %48
store i32 0, i32* %2
br label %60
57: ; preds = %48
br label %28
58: ; preds = %28
br label %8
59: ; preds = %8
store i32 1, i32* %2
br label %60
60: ; preds = %59, %56, %47, %39, %26
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
define i32 @check_grid([9 x i32]* %0) {
%2 = bitcast [9 x i32]* %0 to i32**
br label %6
3: ; preds = %15
%4 = add nsw i32 %7, -1
%5 = icmp eq i32 %7, 0
br i1 %5, label %28, label %6
6: ; preds = %1, %3
%7 = phi i32 [ 80, %1 ], [ %4, %3 ]
%8 = udiv i32 %7, 9
%9 = urem i32 %7, 9
%10 = zext i32 %8 to i64
%11 = zext i32 %9 to i64
%12 = getelementptr inbounds [9 x i32], [9 x i32]* %0, i64 %10, i64 %11
%13 = load i32, i32* %12
%14 = icmp sgt i32 %13, 9
br i1 %14, label %28, label %15
15: ; preds = %6, %25
%16 = phi i32 [ %17, %25 ], [ 0, %6 ]
%17 = add nuw nsw i32 %16, 1
%18 = icmp eq i32 %16, 9
br i1 %18, label %3, label %19
19: ; preds = %15
%20 = tail call i32 @count_key_line(i32** %2, i32 %8, i32 %17)
%21 = icmp sgt i32 %20, 1
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = tail call i32 @count_key_column(i32** %2, i32 %9, i32 %17)
%24 = icmp sgt i32 %23, 1
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @count_key_block(i32** %2, i32 %8, i32 %9, i32 %17)
%27 = icmp sgt i32 %26, 1
br i1 %27, label %28, label %15
28: ; preds = %3, %6, %25, %22, %19
%29 = phi i32 [ 0, %19 ], [ 0, %22 ], [ 0, %25 ], [ 1, %3 ], [ 0, %6 ]
ret i32 %29
}