#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 sudoku {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ sudoku_put(struct sudoku *, int, int, int);
void load_puzzle(int expected_id, FILE *fs, struct sudoku *S) {
  char line[16];
  int id;
  int i, j;
  fscanf(fs, "%s %d", line, &id);
  if (0 != strcmp("Grid", line)) {
    printf("Expected Grid, got %s\n", line);
    exit(EXIT_FAILURE);
  }
  if (expected_id != id) {
    printf("Expected id %d, got %d\n", expected_id, id);
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < 9; ++i) {
    fscanf(fs, "%s", line);
    if (strlen(line) != 9) {
      printf("strlen(%s) is %zu, should be 9\n", line, strlen(line));
      exit(EXIT_FAILURE);
    }
    for (j = 0; j < 9; ++j) {
      sudoku_put(S, i, j, (int)(line[j] - '0'));
    }
  }
}


x86 assembly (clang, -O0):
<load_puzzle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe7e(%rip),%rsi
lea    -0x34(%rbp),%rcx
mov    $0x0,%al
call   1050 <fscanf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1060 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11cb <load_puzzle+0x6b>
lea    -0x30(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     11f9 <load_puzzle+0x99>
mov    -0x4(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x9,-0x38(%rbp)
jge    12b2 <load_puzzle+0x152>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1050 <fscanf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x9,%eax
je     1265 <load_puzzle+0x105>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x9,-0x3c(%rbp)
jge    129f <load_puzzle+0x13f>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x3c(%rbp),%edx
movslq -0x3c(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%ecx
sub    $0x30,%ecx
call   1080 <sudoku_put@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    126c <load_puzzle+0x10c>
jmp    12a4 <load_puzzle+0x144>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1200 <load_puzzle+0xa0>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_puzzle>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xe84(%rip),%rsi
mov    %rsp,%rbp
lea    0x1c(%rsp),%rcx
mov    %r14,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
lea    0xe6e(%rip),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1301 <load_puzzle+0x1a1>
mov    0x1c(%rsp),%edx
cmp    %r15d,%edx
jne    1314 <load_puzzle+0x1b4>
lea    0xe7d(%rip),%r15
mov    %rsp,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fscanf@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    $0x9,%eax
jne    12d5 <load_puzzle+0x175>
movsbl (%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1080 <sudoku_put@plt>
movsbl 0x1(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   1080 <sudoku_put@plt>
movsbl 0x2(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1080 <sudoku_put@plt>
movsbl 0x3(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   1080 <sudoku_put@plt>
movsbl 0x4(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x4,%edx
call   1080 <sudoku_put@plt>
movsbl 0x5(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x5,%edx
call   1080 <sudoku_put@plt>
movsbl 0x6(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x6,%edx
call   1080 <sudoku_put@plt>
movsbl 0x7(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x7,%edx
call   1080 <sudoku_put@plt>
movsbl 0x8(%rsp),%ecx
add    $0xffffffd0,%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x8,%edx
call   1080 <sudoku_put@plt>
add    $0x1,%ebp
cmp    $0x9,%ebp
jne    11d0 <load_puzzle+0x70>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xd56(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xd03(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12f3 <load_puzzle+0x193>
lea    0xd07(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12f3 <load_puzzle+0x193>

LLVM IR (-O0):
%struct.sudoku = type { i32 }
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [5 x i8] c"Grid\00"
@.str.2 = [23 x i8] c"Expected Grid, got %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [24 x i8] c"Expected id %d, got %d\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [32 x i8] c"strlen(%s) is %zu, should be 9\0A\00"
define void @load_puzzle(i32 %0, i32* %1, %struct.sudoku* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.sudoku*
%7 = alloca [16 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store %struct.sudoku* %2, %struct.sudoku** %6
%11 = load i32*, i32** %5
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%13 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i32* %8)
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%15 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %3
%23 = load i32, i32* %4
%24 = load i32, i32* %8
%25 = icmp ne i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i32, i32* %4
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %27, i32 %28)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %22
store i32 0, i32* %9
br label %33
33: ; preds = %69, %32
%34 = load i32, i32* %9
%35 = icmp slt i32 %34, 9
br i1 %35, label %36, label %72
36: ; preds = %33
%37 = load i32*, i32** %5
%38 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%39 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %38)
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = icmp ne i32 %41, 9
br i1 %42, label %43, label %50
43: ; preds = %36
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %44, i32 %46)
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %36
store i32 0, i32* %10
br label %51
51: ; preds = %65, %50
%52 = load i32, i32* %10
%53 = icmp slt i32 %52, 9
br i1 %53, label %54, label %68
54: ; preds = %51
%55 = load %struct.sudoku*, %struct.sudoku** %6
%56 = load i32, i32* %9
%57 = load i32, i32* %10
%58 = load i32, i32* %10
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = sub nsw i32 %62, 48
%64 = call i32 @sudoku_put(%struct.sudoku* %55, i32 %56, i32 %57, i32 %63)
br label %65
65: ; preds = %54
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %51
68: ; preds = %51
br label %69
69: ; preds = %68
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %33
72: ; preds = %33
ret void
}

LLVM IR (-O2):
%struct.sudoku = type { i32 }
@.str = [6 x i8] c"%s %d\00"
@.str.1 = [5 x i8] c"Grid\00"
@.str.2 = [23 x i8] c"Expected Grid, got %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [24 x i8] c"Expected id %d, got %d\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [32 x i8] c"strlen(%s) is %zu, should be 9\0A\00"
define void @load_puzzle(i32 %0, i32* nocapture %1, %struct.sudoku* %2) {
%4 = alloca [16 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %5)
%9 = call i64 @strcmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %3
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %3
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, %0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 1
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 2
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 3
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 4
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 5
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 6
%25 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 7
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 8
br label %31
27: ; preds = %15
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %16)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %18, %36
%32 = phi i32 [ %73, %36 ], [ 0, %18 ]
%33 = call i32 (i32*, i8*, i8*, ...) @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%34 = call i32 @strlen(i8* %6)
%35 = icmp eq i32 %34, 9
br i1 %35, label %36, label %75
36: ; preds = %31
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = add nsw i32 %38, -48
%40 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 0, i32 %39)
%41 = load i8, i8* %19
%42 = sext i8 %41 to i32
%43 = add nsw i32 %42, -48
%44 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 1, i32 %43)
%45 = load i8, i8* %20
%46 = sext i8 %45 to i32
%47 = add nsw i32 %46, -48
%48 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 2, i32 %47)
%49 = load i8, i8* %21
%50 = sext i8 %49 to i32
%51 = add nsw i32 %50, -48
%52 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 3, i32 %51)
%53 = load i8, i8* %22
%54 = sext i8 %53 to i32
%55 = add nsw i32 %54, -48
%56 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 4, i32 %55)
%57 = load i8, i8* %23
%58 = sext i8 %57 to i32
%59 = add nsw i32 %58, -48
%60 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 5, i32 %59)
%61 = load i8, i8* %24
%62 = sext i8 %61 to i32
%63 = add nsw i32 %62, -48
%64 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 6, i32 %63)
%65 = load i8, i8* %25
%66 = sext i8 %65 to i32
%67 = add nsw i32 %66, -48
%68 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 7, i32 %67)
%69 = load i8, i8* %26
%70 = sext i8 %69 to i32
%71 = add nsw i32 %70, -48
%72 = call i32 @sudoku_put(%struct.sudoku* %2, i32 %32, i32 8, i32 %71)
%73 = add nuw nsw i32 %32, 1
%74 = icmp eq i32 %73, 9
br i1 %74, label %80, label %31
75: ; preds = %31
%76 = call i32 @strlen(i8* %6)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %6, i32 %76)
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; preds = %36
ret void
}