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

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int get_digit_value(unsigned int);
int /*<<< orphan*/ *stderr;
void output_digit_test(const char *filename, const char *version) {
  FILE *stream;
  bool need_comma;
  unsigned int ch;
  stream = fopen(filename, "w");
  if (stream == NULL) {
    fprintf(stderr, "cannot open '%s' for writing\n", filename);
    exit(1);
  }
  fprintf(stream, "/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\n");
  fprintf(stream, "/* Digit values of Unicode characters.  */\n");
  fprintf(
      stream,
      "/* Generated automatically by gen-uni-tables.c for Unicode %s.  */\n",
      version);
  need_comma = false;
  for (ch = 0; ch < 0x110000; ch++) {
    int value = get_digit_value(ch);
    if (!(value >= -1 && value < 10))
      abort();
    if (value >= 0) {
      if (need_comma)
        fprintf(stream, ",\n");
      fprintf(stream, "    { 0x%04X, %d }", ch, value);
      need_comma = true;
    }
  }
  if (need_comma)
    fprintf(stream, "\n");
  if (ferror(stream) || fclose(stream)) {
    fprintf(stderr, "error writing to '%s'\n", filename);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<output_digit_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <output_digit_test+0x55>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe4e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x110000,-0x20(%rbp)
jae    1298 <output_digit_test+0x128>
mov    -0x20(%rbp),%edi
call   1070 <get_digit_value@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jl     1239 <output_digit_test+0xc9>
cmpl   $0xa,-0x24(%rbp)
jl     1240 <output_digit_test+0xd0>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x24(%rbp)
jl     1285 <output_digit_test+0x115>
cmpl   $0x0,-0x1c(%rbp)
je     1266 <output_digit_test+0xf6>
mov    -0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    128a <output_digit_test+0x11a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    120d <output_digit_test+0x9d>
cmpl   $0x0,-0x1c(%rbp)
je     12b4 <output_digit_test+0x144>
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
jne    12da <output_digit_test+0x16a>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
cmp    $0x0,%rax
je     1300 <output_digit_test+0x190>
mov    0x2cff(%rip),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_digit_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d6 <output_digit_test+0x146>
mov    %rax,%r13
lea    0xe60(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10b0 <fwrite@plt>
lea    0xe74(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10b0 <fwrite@plt>
lea    0xe87(%rip),%rsi
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%r12b
lea    0xeb5(%rip),%r15
mov    %ebp,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1080 <get_digit_value@plt>
mov    %eax,%ebp
lea    0x1(%rbp),%eax
cmp    $0xb,%eax
jae    12bc <output_digit_test+0x12c>
test   %ebp,%ebp
jns    1240 <output_digit_test+0xb0>
add    $0x1,%ebx
cmp    $0x110000,%ebx
jne    1210 <output_digit_test+0x80>
jmp    1280 <output_digit_test+0xf0>
cs nopw 0x0(%rax,%rax,1)
test   $0x1,%r12b
jne    125f <output_digit_test+0xcf>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe66(%rip),%rdi
mov    %r13,%rcx
call   10b0 <fwrite@plt>
xor    %r12d,%r12d
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
lea    0x1(%rbx),%ebp
cmp    $0x10ffff,%ebx
jne    120b <output_digit_test+0x7b>
jmp    1286 <output_digit_test+0xf6>
test   $0x1,%r12b
jne    1293 <output_digit_test+0x103>
mov    $0xa,%edi
mov    %r13,%rsi
call   1060 <fputc@plt>
mov    %r13,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12c3 <output_digit_test+0x133>
mov    %r13,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
jne    12c3 <output_digit_test+0x133>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%rdi
lea    0xdff(%rip),%rsi
jmp    12e7 <output_digit_test+0x157>
mov    0x2d03(%rip),%rax
mov    (%rax),%rdi
lea    0xd1b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.1 = [30 x i8] c"cannot open '%s' for writing\0A\00"
@.str.2 = [45 x i8] c"/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\0A\00"
@.str.3 = [44 x i8] c"/* Digit values of Unicode characters. */\0A\00"
@.str.4 = [68 x i8] c"/* Generated automatically by gen-uni-tables.c for Unicode %s. */\0A\00"
@.str.5 = [3 x i8] c",\0A\00"
@.str.6 = [19 x i8] c" { 0x%04X, %d }\00"
@.str.7 = [2 x i8] c"\0A\00"
@.str.8 = [23 x i8] c"error writing to '%s'\0A\00"
define void @output_digit_test(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32*, i32** @stderr
%15 = load i8*, i8** %3
%16 = call i32 (i32*, i8*, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32*, i32** %5
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32*, i32** %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32*, i32** %5
%24 = load i8*, i8** %4
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* %24)
store i32 0, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %54, %18
%27 = load i32, i32* %7
%28 = icmp ult i32 %27, 1114112
br i1 %28, label %29, label %57
29: ; preds = %26
%30 = load i32, i32* %7
%31 = call i32 @get_digit_value(i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sge i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 10
br i1 %36, label %39, label %37
37: ; preds = %34, %29
%38 = call i32 (...) @abort()
unreachable
39: ; preds = %34
%40 = load i32, i32* %8
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %39
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32*, i32** %5
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %45, %42
%49 = load i32*, i32** %5
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %50, i32 %51)
store i32 1, i32* %6
br label %53
53: ; preds = %48, %39
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add i32 %55, 1
store i32 %56, i32* %7
br label %26
57: ; preds = %26
%58 = load i32, i32* %6
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32*, i32** %5
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %60, %57
%64 = load i32*, i32** %5
%65 = call i64 @ferror(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %63
%68 = load i32*, i32** %5
%69 = call i64 @fclose(i32* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %67, %63
%72 = load i32*, i32** @stderr
%73 = load i8*, i8** %3
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %73)
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %67
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32* null
@.str.1 = [30 x i8] c"cannot open '%s' for writing\0A\00"
@.str.2 = [45 x i8] c"/* DO NOT EDIT! GENERATED AUTOMATICALLY! */\0A\00"
@.str.3 = [44 x i8] c"/* Digit values of Unicode characters. */\0A\00"
@.str.4 = [68 x i8] c"/* Generated automatically by gen-uni-tables.c for Unicode %s. */\0A\00"
@.str.5 = [3 x i8] c",\0A\00"
@.str.6 = [19 x i8] c" { 0x%04X, %d }\00"
@.str.8 = [23 x i8] c"error writing to '%s'\0A\00"
define void @output_digit_test(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32*, i32** @stderr
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 44, i64 1, i32* %3)
%11 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i64 43, i64 1, i32* %3)
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.4, i64 0, i64 0), i8* %1)
br label %13
13: ; preds = %31, %9
%14 = phi i1 [ false, %31 ], [ true, %9 ]
%15 = phi i32 [ %33, %31 ], [ 0, %9 ]
br label %16
16: ; preds = %13, %28
%17 = phi i32 [ %29, %28 ], [ %15, %13 ]
%18 = tail call i32 @get_digit_value(i32 %17)
%19 = add i32 %18, 1
%20 = icmp ult i32 %19, 11
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = tail call i32 (...) @abort()
unreachable
23: ; preds = %16
%24 = icmp sgt i32 %18, -1
br i1 %24, label %25, label %28
25: ; preds = %23
br i1 %14, label %31, label %26
26: ; preds = %25
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i64 2, i64 1, i32* %3)
br label %31
28: ; preds = %23
%29 = add nuw nsw i32 %17, 1
%30 = icmp eq i32 %29, 1114112
br i1 %30, label %35, label %16
31: ; preds = %25, %26
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %17, i32 %18)
%33 = add nuw nsw i32 %17, 1
%34 = icmp eq i32 %33, 1114112
br i1 %34, label %36, label %13
35: ; preds = %28
br i1 %14, label %38, label %36
36: ; preds = %31, %35
%37 = tail call i32 @fputc(i32 10, i32* %3)
br label %38
38: ; preds = %36, %35
%39 = tail call i64 @ferror(i32* %3)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = tail call i64 @fclose(i32* %3)
%43 = icmp eq i64 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41, %38
%45 = load i32*, i32** @stderr
%46 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%47 = tail call i32 @exit(i32 1)
unreachable
48: ; preds = %41
ret void
}