#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 nl_item;

/* Variables and functions */
int ALT_DIGITS;
int ERA;
int /*<<< orphan*/ LC_ALL;
char *nl_langinfo(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putenv(char *);
char *setlocale(int /*<<< orphan*/, char *);
int strlen(char *);
int main(void) {
  nl_item key;
  char *p, *l;
  int i, n;
  key = ERA;
  key = ALT_DIGITS;
  putenv("LANGUAGE=ja_JP");
  putenv("LANG=ja_JP");
  l = setlocale(LC_ALL, "");
  printf("locale \"%s\"\n", l);
  p = nl_langinfo(key);
  printf("key %#X %p '%s'\n", key, p, p);
  for (n = 0;; n++) {
    int len = strlen(p);
    if (len == 0)
      break;
    printf("  %d %p '%s'", n, p, p);
    for (i = 0; i < len; i++) {
      printf(" %02X", (int)(unsigned char)p[i]);
    }
    printf("\n");
    p += len + 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
lea    0xe82(%rip),%rdi
call   1050 <putenv@plt>
lea    0xe85(%rip),%rdi
call   1050 <putenv@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
call   1070 <setlocale@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <nl_langinfo@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1201 <main+0xb1>
jmp    1285 <main+0x135>
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1255 <main+0x105>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1221 <main+0xd1>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e6 <main+0x96>
xor    %eax,%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
mov    0x2e6e(%rip),%rax
mov    (%rax),%ebp
lea    0xe85(%rip),%rdi
call   1060 <putenv@plt>
lea    0xe88(%rip),%rdi
call   1060 <putenv@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe8a(%rip),%rsi
call   1080 <setlocale@plt>
lea    0xe72(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1070 <nl_langinfo@plt>
mov    %rax,%rbx
lea    0xe64(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     125a <main+0xfa>
mov    %eax,%r12d
lea    0xe5d(%rip),%r15
xor    %r13d,%r13d
jmp    1217 <main+0xb7>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq %r12d,%rax
add    %rax,%rbx
add    $0x1,%rbx
add    $0x1,%r13d
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
test   %eax,%eax
je     125a <main+0xfa>
lea    0xe1a(%rip),%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
test   %r12d,%r12d
jle    11f0 <main+0x90>
mov    %r12d,%ebp
xor    %r14d,%r14d
nopl   0x0(%rax)
movzbl (%rbx,%r14,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbp
jne    1240 <main+0xe0>
jmp    11f0 <main+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ERA = global i32 0
@ALT_DIGITS = global i32 0
@.str = [15 x i8] c"LANGUAGE=ja_JP\00"
@.str.1 = [11 x i8] c"LANG=ja_JP\00"
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [13 x i8] c"locale \22%s\22\0A\00"
@.str.4 = [17 x i8] c"key %#X %p '%s'\0A\00"
@.str.5 = [13 x i8] c" %d %p '%s'\00"
@.str.6 = [6 x i8] c" %02X\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @ERA
store i32 %8, i32* %2
%9 = load i32, i32* @ALT_DIGITS
store i32 %9, i32* %2
%10 = call i32 @putenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @putenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @LC_ALL
%13 = call i8* @setlocale(i32 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %2
%17 = call i8* @nl_langinfo(i32 %16)
store i8* %17, i8** %3
%18 = load i32, i32* %2
%19 = load i8*, i8** %3
%20 = load i8*, i8** %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %18, i8* %19, i8* %20)
store i32 0, i32* %6
br label %22
22: ; preds = %55, %0
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
br label %58
28: ; preds = %22
%29 = load i32, i32* %6
%30 = load i8*, i8** %3
%31 = load i8*, i8** %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %29, i8* %30, i8* %31)
store i32 0, i32* %5
br label %33
33: ; preds = %45, %28
%34 = load i32, i32* %5
%35 = load i32, i32* %7
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %48
37: ; preds = %33
%38 = load i8*, i8** %3
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %37
%46 = load i32, i32* %5
%47 = add nsw i32 %46, 1
store i32 %47, i32* %5
br label %33
48: ; preds = %33
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
%52 = load i8*, i8** %3
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %3
br label %55
55: ; preds = %48
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %22
58: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@ERA = global i32 0
@ALT_DIGITS = global i32 0
@.str = [15 x i8] c"LANGUAGE=ja_JP\00"
@.str.1 = [11 x i8] c"LANG=ja_JP\00"
@LC_ALL = global i32 0
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [13 x i8] c"locale \22%s\22\0A\00"
@.str.4 = [17 x i8] c"key %#X %p '%s'\0A\00"
@.str.5 = [13 x i8] c" %d %p '%s'\00"
@.str.6 = [6 x i8] c" %02X\00"
define i32 @main() {
%1 = load i32, i32* @ALT_DIGITS
%2 = tail call i32 @putenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @putenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%4 = load i32, i32* @LC_ALL
%5 = tail call i8* @setlocale(i32 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%7 = tail call i8* @nl_langinfo(i32 %1)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %1, i8* %7, i8* %7)
%9 = tail call i32 @strlen(i8* %7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %35, label %11
11: ; preds = %0, %27
%12 = phi i32 [ %33, %27 ], [ %9, %0 ]
%13 = phi i32 [ %32, %27 ], [ 0, %0 ]
%14 = phi i8* [ %31, %27 ], [ %7, %0 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %13, i8* %14, i8* %14)
%16 = icmp sgt i32 %12, 0
br i1 %16, label %17, label %27
17: ; preds = %11
%18 = zext i32 %12 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %25, %19 ]
%21 = getelementptr inbounds i8, i8* %14, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %18
br i1 %26, label %27, label %19
27: ; preds = %19, %11
%28 = tail call i32 @putchar(i32 10)
%29 = add nsw i32 %12, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %14, i64 %30
%32 = add nuw nsw i32 %13, 1
%33 = tail call i32 @strlen(i8* %31)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %11
35: ; preds = %27, %0
ret i32 0
}