#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 stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ fstat(int /*<<< orphan*/, struct stat *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  FILE *lmm;
  FILE *lso;
  struct stat fd_stat;
  int c;
  size_t i;
  if (!(lmm = fopen("locale.mmap", "r"))) {
    printf("can't open locale.mmap!\n");
    return EXIT_FAILURE;
  }
  if (fstat(fileno(lmm), &fd_stat)) {
    printf("can't stat locale.mmap!\n");
    fclose(lmm);
    return EXIT_FAILURE;
  }
  if (!(lso = fopen("locale_data.c", "w"))) {
    printf("can't open locale_data.c!\n");
    fclose(lmm);
    return EXIT_FAILURE;
  }
  fprintf(lso,
          "#include <stddef.h>\n"
          "#include <stdint.h>\n"
          "#include \"lt_defines.h\"\n"
          "#include \"locale_mmap.h\"\n\n"
          "typedef union {\n"
          "\tunsigned char buf[%zu];\n"
          "\t__locale_mmap_t lmm;\n"
          "} locale_union_t;\n\n"
          "static const locale_union_t locale_union = { {",
          (size_t)fd_stat.st_size);
  i = 0;
  while ((c = getc(lmm)) != EOF) {
    if (!(i & 0x7)) {
      fprintf(lso, "\n\t");
    }
    fprintf(lso, "%#04x, ", c);
    ++i;
  }
  fprintf(lso, "\n} };\n\n"
               "const __locale_mmap_t *__locale_mmap = &locale_union.lmm;\n\n");
  if (ferror(lmm)) {
    printf("error reading!\n");
    return EXIT_FAILURE;
  }
  if (ferror(lso) || fclose(lso)) {
    printf("error writing!\n");
    return EXIT_FAILURE;
  }
  fclose(lmm);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe6f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11cd <main+0x4d>
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x10(%rbp),%rdi
call   1070 <fileno@plt>
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1090 <fstat@plt>
cmp    $0x0,%rax
je     1211 <main+0x91>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1375 <main+0x1f5>
lea    0xe28(%rip),%rdi
lea    0xe2f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1258 <main+0xd8>
lea    0xe17(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2d5f(%rip),%rcx
cmp    (%rcx),%eax
je     12db <main+0x15b>
mov    -0x30(%rbp),%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    12b5 <main+0x135>
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1276 <main+0xf6>
mov    -0x18(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     131d <main+0x19d>
lea    0xe8d(%rip),%rdi
call   1050 <printf@plt>
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
jne    1343 <main+0x1c3>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1360 <main+0x1e0>
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1375 <main+0x1f5>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e3 <main+0x53>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fileno@plt>
mov    %rsp,%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
test   %rax,%rax
je     1207 <main+0x77>
lea    0xfc3(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11ef <main+0x5f>
lea    0xf5d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe00(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     127e <main+0xee>
mov    %rax,%r14
mov    (%rsp),%rdx
lea    0xdf1(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    0x2da2(%rip),%r13
cmp    0x0(%r13),%eax
jne    128a <main+0xfa>
lea    0xeb1(%rip),%rdi
mov    $0x42,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     12e4 <main+0x154>
lea    0xf0f(%rip),%rdi
jmp    11ea <main+0x5a>
lea    0xeda(%rip),%rdi
jmp    11d4 <main+0x44>
mov    %eax,%ebp
lea    0xe69(%rip),%r12
xor    %r15d,%r15d
jmp    12c3 <main+0x133>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r15
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %eax,%ebp
cmp    0x0(%r13),%eax
je     124c <main+0xbc>
test   $0x7,%r15b
jne    12a0 <main+0x110>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe1f(%rip),%rdi
mov    %r14,%rcx
call   1090 <fwrite@plt>
jmp    12a0 <main+0x110>
mov    %r14,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
jne    12fe <main+0x16e>
mov    %r14,%rdi
call   1050 <fclose@plt>
test   %rax,%rax
je     130a <main+0x17a>
lea    0xe74(%rip),%rdi
jmp    11ea <main+0x5a>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2cb7(%rip),%rax
jmp    11f6 <main+0x66>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [12 x i8] c"locale.mmap\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"can't open locale.mmap!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [25 x i8] c"can't stat locale.mmap!\0A\00"
@.str.4 = [14 x i8] c"locale_data.c\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [27 x i8] c"can't open locale_data.c!\0A\00"
@.str.7 = [219 x i8] c"#include <stddef.h>\0A#include <stdint.h>\0A#include \22lt_defines.h\22\0A#include \22locale_mmap.h\22\0A\0Atypedef union {\0A\09unsigned char buf[%zu];\0A\09__locale_mmap_t lmm;\0A} locale_union_t;\0A\0Astatic const locale_union_t locale_union = { {\00"
@EOF = global i32 0
@.str.8 = [3 x i8] c"\0A\09\00"
@.str.9 = [8 x i8] c"%x, \00"
@.str.10 = [67 x i8] c"\0A} };\0A\0Aconst __locale_mmap_t *__locale_mmap = &locale_union.lmm;\0A\0A\00"
@.str.11 = [16 x i8] c"error reading!\0A\00"
@.str.12 = [16 x i8] c"error writing!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = icmp ne i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
store i32 %11, i32* %1
br label %77
12: ; preds = %0
%13 = load i32*, i32** %2
%14 = call i32 @fileno(i32* %13)
%15 = call i64 @fstat(i32 %14, %struct.stat* %4)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32*, i32** %2
%20 = call i64 @fclose(i32* %19)
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %1
br label %77
22: ; preds = %12
%23 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %23, i32** %3
%24 = icmp ne i32* %23, null
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%27 = load i32*, i32** %2
%28 = call i64 @fclose(i32* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %1
br label %77
30: ; preds = %22
%31 = load i32*, i32** %3
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%33 = load i64, i64* %32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str.7, i64 0, i64 0), i64 %33)
store i64 0, i64* %6
br label %35
35: ; preds = %47, %30
%36 = load i32*, i32** %2
%37 = call i32 @getc(i32* %36)
store i32 %37, i32* %5
%38 = load i32, i32* @EOF
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %35
%41 = load i64, i64* %6
%42 = and i64 %41, 7
%43 = icmp ne i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %40
%45 = load i32*, i32** %3
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %47
47: ; preds = %44, %40
%48 = load i32*, i32** %3
%49 = load i32, i32* %5
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 %49)
%51 = load i64, i64* %6
%52 = add i64 %51, 1
store i64 %52, i64* %6
br label %35
53: ; preds = %35
%54 = load i32*, i32** %3
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.10, i64 0, i64 0))
%56 = load i32*, i32** %2
%57 = call i64 @ferror(i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %1
br label %77
62: ; preds = %53
%63 = load i32*, i32** %3
%64 = call i64 @ferror(i32* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %62
%67 = load i32*, i32** %3
%68 = call i64 @fclose(i32* %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %66, %62
%71 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.12, i64 0, i64 0))
%72 = load i32, i32* @EXIT_FAILURE
store i32 %72, i32* %1
br label %77
73: ; preds = %66
%74 = load i32*, i32** %2
%75 = call i64 @fclose(i32* %74)
%76 = load i32, i32* @EXIT_SUCCESS
store i32 %76, i32* %1
br label %77
77: ; preds = %73, %70, %59, %25, %17, %9
%78 = load i32, i32* %1
ret i32 %78
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [12 x i8] c"locale.mmap\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.4 = [14 x i8] c"locale_data.c\00"
@.str.5 = [2 x i8] c"w\00"
@.str.7 = [219 x i8] c"#include <stddef.h>\0A#include <stdint.h>\0A#include \22lt_defines.h\22\0A#include \22locale_mmap.h\22\0A\0Atypedef union {\0A\09unsigned char buf[%zu];\0A\09__locale_mmap_t lmm;\0A} locale_union_t;\0A\0Astatic const locale_union_t locale_union = { {\00"
@EOF = global i32 0
@.str.8 = [3 x i8] c"\0A\09\00"
@.str.9 = [8 x i8] c"%x, \00"
@.str.10 = [67 x i8] c"\0A} };\0A\0Aconst __locale_mmap_t *__locale_mmap = &locale_union.lmm;\0A\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [24 x i8] c"can't open locale.mmap!\00"
@str.13 = [26 x i8] c"can't open locale_data.c!\00"
@str.14 = [15 x i8] c"error writing!\00"
@str.15 = [15 x i8] c"error reading!\00"
@str.16 = [24 x i8] c"can't stat locale.mmap!\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %56
7: ; preds = %0
%8 = tail call i32 @fileno(i32* %3)
%9 = call i64 @fstat(i32 %8, %struct.stat* %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.16, i64 0, i64 0))
%13 = tail call i64 @fclose(i32* %3)
br label %56
14: ; preds = %7
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
%19 = tail call i64 @fclose(i32* %3)
br label %56
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%22 = load i64, i64* %21
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([219 x i8], [219 x i8]* @.str.7, i64 0, i64 0), i64 %22)
%24 = tail call i32 @getc(i32* %3)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %40, label %27
27: ; preds = %20, %34
%28 = phi i32 [ %37, %34 ], [ %24, %20 ]
%29 = phi i64 [ %36, %34 ], [ 0, %20 ]
%30 = and i64 %29, 7
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i64 2, i64 1, i32* %15)
br label %34
34: ; preds = %32, %27
%35 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 %28)
%36 = add i64 %29, 1
%37 = tail call i32 @getc(i32* %3)
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %27
40: ; preds = %34, %20
%41 = tail call i64 @fwrite(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.10, i64 0, i64 0), i64 66, i64 1, i32* %15)
%42 = tail call i64 @ferror(i32* %3)
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.15, i64 0, i64 0))
br label %56
46: ; preds = %40
%47 = tail call i64 @ferror(i32* %15)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %46
%50 = tail call i64 @fclose(i32* %15)
%51 = icmp eq i64 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %49, %46
%53 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.14, i64 0, i64 0))
br label %56
54: ; preds = %49
%55 = tail call i64 @fclose(i32* %3)
br label %56
56: ; preds = %54, %52, %44, %17, %11, %5
%57 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %44 ], [ @EXIT_FAILURE, %52 ], [ @EXIT_SUCCESS, %54 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_FAILURE, %5 ]
%58 = load i32, i32* %57
ret i32 %58
}