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

/* Variables and functions */
int /*<<< orphan*/ LC_ALL;
char *MB_CUR_MAX;
int mbstowcs(int *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
char *setlocale(int /*<<< orphan*/, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
scalar_t__ wcscmp(int *, char *);
int wcslen(int *);
int wcstombs(char *, int *, int);
scalar_t__ wctomb(char *, int);
int main(void) {
  int test = 0;
  int idx = 0;
  char buf[100], *pchar;
  wchar_t tmp[10];
  wchar_t tmp1[] = {L'W', L'o', L'r', L'l', L'd', L'\0'};
  char str[] = "Hello";
  int result = 0;
  pchar = setlocale(LC_ALL, "");
  printf("locale : %s\n", pchar);
  printf("MB_CUR_MAX %Zd\n", MB_CUR_MAX);
  puts("---- test 1 ------");
  test = mbstowcs(tmp, str, (strlen(str) + 1) * sizeof(char));
  printf("size of string by mbstowcs %d\n", test);
  if (test != strlen(str))
    result = 1;
  idx += wctomb(&buf[0], tmp[0]);
  idx += wctomb(&buf[idx], tmp[1]);
  buf[idx] = 0;
  printf("orig string %s\n", str);
  printf("string by wctomb %s\n", buf);
  printf("string by %%C %C", tmp[0]);
  if (tmp[0] != L'H')
    result = 1;
  printf("%C\n", tmp[1]);
  if (tmp[1] != L'e')
    result = 1;
  printf("string by %%S %S\n", tmp);
  if (wcscmp(tmp, L"Hello") != 0)
    result = 1;
  puts("---- test 2 ------");
  printf("wchar string %S\n", tmp1);
  printf("wchar %C\n", tmp1[0]);
  test = wcstombs(buf, tmp1, (wcslen(tmp1) + 1) * sizeof(wchar_t));
  printf("size of string by wcstombs %d\n", test);
  if (test != wcslen(tmp1))
    result = 1;
  test = wcslen(tmp1);
  printf("size of string by wcslen %d\n", test);
  printf("char %s\n", buf);
  if (strcmp(buf, "World") != 0)
    result = 1;
  puts("------------------");
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0xe39(%rip),%rax
mov    %rax,-0xc0(%rbp)
mov    0xe33(%rip),%rax
mov    %rax,-0xb8(%rbp)
mov    0xe2d(%rip),%rax
mov    %rax,-0xb0(%rbp)
mov    0xe28(%rip),%eax
mov    %eax,-0xc6(%rbp)
mov    0xe1f(%rip),%ax
mov    %ax,-0xc2(%rbp)
movl   $0x0,-0xcc(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
call   10a0 <setlocale@plt>
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xde3(%rip),%rdi
call   1040 <puts@plt>
lea    -0xa0(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0xc6(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0xc6(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1050 <mbstowcs@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xd0(%rbp)
lea    -0xc6(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0xd0(%rbp),%eax
cmp    %ecx,%eax
je     12e6 <main+0x146>
movl   $0x1,-0xcc(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0xa0(%rbp),%esi
call   10b0 <wctomb@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
lea    -0x70(%rbp),%rdi
add    %rax,%rdi
mov    -0x9c(%rbp),%esi
call   10b0 <wctomb@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0xc6(%rbp),%rsi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xa0(%rbp),%esi
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x48,-0xa0(%rbp)
je     1380 <main+0x1e0>
movl   $0x1,-0xcc(%rbp)
mov    -0x9c(%rbp),%esi
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
cmpl   $0x65,-0x9c(%rbp)
je     13ab <main+0x20b>
movl   $0x1,-0xcc(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1030 <wcscmp@plt>
cmp    $0x0,%rax
je     13e7 <main+0x247>
movl   $0x1,-0xcc(%rbp)
lea    0xcc7(%rip),%rdi
call   1040 <puts@plt>
lea    -0xc0(%rbp),%rsi
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc0(%rbp),%esi
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xc0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    -0xf8(%rbp),%rdi
mov    -0xf0(%rbp),%rsi
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
call   10c0 <wcstombs@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xc77(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xe4(%rbp)
lea    -0xc0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %eax,%ecx
mov    -0xe4(%rbp),%eax
cmp    %ecx,%eax
je     14a2 <main+0x302>
movl   $0x1,-0xcc(%rbp)
lea    -0xc0(%rbp),%rdi
call   1080 <wcslen@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xc47(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xc52(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xc49(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     14f8 <main+0x358>
movl   $0x1,-0xcc(%rbp)
lea    0xc2f(%rip),%rdi
call   1040 <puts@plt>
mov    -0xcc(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
mov    0xe58(%rip),%rax
mov    %rax,0x50(%rsp)
movaps 0xe3c(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movw   $0x6f,0xc(%rsp)
movl   $0x6c6c6548,0x8(%rsp)
6c
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xefa(%rip),%rsi
call   10a0 <setlocale@plt>
lea    0xe2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rsi
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <mbstowcs@plt>
mov    %eax,%ebp
lea    0xe03(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    %eax,%ebp
setne  0x7(%rsp)
mov    0x10(%rsp),%esi
lea    0x60(%rsp),%r15
mov    %r15,%rdi
call   10b0 <wctomb@plt>
movslq %eax,%rbp
lea    (%rsp,%rbp,1),%rdi
add    $0x60,%rdi
mov    0x14(%rsp),%esi
call   10b0 <wctomb@plt>
add    %eax,%ebp
movslq %ebp,%rax
movb   $0x0,0x60(%rsp,%rax,1)
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdd3(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xdd3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rsp),%esi
cmpl   $0x48,0x10(%rsp)
setne  %bl
lea    0xe06(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmpl   $0x65,0x14(%rsp)
setne  %r13b
lea    0xdb3(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1030 <wcscmp@plt>
test   %rax,%rax
setne  %r12b
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
lea    0xda5(%rip),%rdi
lea    0x40(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x40(%rsp),%esi
lea    0xd9c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1080 <wcslen@plt>
lea    0x4(,%rax,4),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   10c0 <wcstombs@plt>
mov    %eax,%ebp
lea    0xd7c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   1080 <wcslen@plt>
cmp    %eax,%ebp
setne  %bpl
lea    0xd7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd8a(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd82(%rip),%rsi
mov    %r15,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
setne  %al
or     %r12b,%al
or     %bpl,%al
or     %r13b,%al
or     0x7(%rsp),%bl
or     %al,%bl
movzbl %bl,%ebx
lea    0xd61(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.tmp1 = [6 x i32] [i32 87, i32 111, i32 114, i32 108, i32 100, i32 0]
@__const.main.str = [6 x i8] c"Hello\00"
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"locale : %s\0A\00"
@.str.2 = [16 x i8] c"MB_CUR_MAX %Zd\0A\00"
@MB_CUR_MAX = global i8* null
@.str.3 = [19 x i8] c"---- test 1 ------\00"
@.str.4 = [31 x i8] c"size of string by mbstowcs %d\0A\00"
@.str.5 = [16 x i8] c"orig string %s\0A\00"
@.str.6 = [21 x i8] c"string by wctomb %s\0A\00"
@.str.7 = [17 x i8] c"string by %%C %C\00"
@.str.8 = [4 x i8] c"%C\0A\00"
@.str.9 = [18 x i8] c"string by %%S %S\0A\00"
@.str.10 = [6 x i32] [i32 72, i32 101, i32 108, i32 108, i32 111, i32 0]
@.str.11 = [19 x i8] c"---- test 2 ------\00"
@.str.12 = [17 x i8] c"wchar string %S\0A\00"
@.str.13 = [10 x i8] c"wchar %C\0A\00"
@.str.14 = [31 x i8] c"size of string by wcstombs %d\0A\00"
@.str.15 = [29 x i8] c"size of string by wcslen %d\0A\00"
@.str.16 = [9 x i8] c"char %s\0A\00"
@.str.17 = [6 x i8] c"World\00"
@.str.18 = [19 x i8] c"------------------\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca [10 x i32]
%7 = alloca [6 x i32]
%8 = alloca [6 x i8]
%9 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%10 = bitcast [6 x i32]* %7 to i8*
%11 = bitcast [6 x i8]* %8 to i8*
store i32 0, i32* %9
%12 = load i32, i32* @LC_ALL
%13 = call i8* @setlocale(i32 %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** @MB_CUR_MAX
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%18 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%21 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
%27 = call i32 @mbstowcs(i32* %19, i8* %20, i32 %26)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%32 = call i32 @strlen(i8* %31)
%33 = icmp ne i32 %30, %32
br i1 %33, label %34, label %35
34: ; preds = %0
store i32 1, i32* %9
br label %35
35: ; preds = %34, %0
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%38 = load i32, i32* %37
%39 = call i64 @wctomb(i8* %36, i32 %38)
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %45
%47 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i64 @wctomb(i8* %46, i32 %48)
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [6 x i8], [6 x i8]* %8, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %57)
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %59)
%61 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%62 = load i32, i32* %61
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%65 = load i32, i32* %64
%66 = icmp ne i32 %65, 72
br i1 %66, label %67, label %68
67: ; preds = %35
store i32 1, i32* %9
br label %68
68: ; preds = %67, %35
%69 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 1
%73 = load i32, i32* %72
%74 = icmp ne i32 %73, 101
br i1 %74, label %75, label %76
75: ; preds = %68
store i32 1, i32* %9
br label %76
76: ; preds = %75, %68
%77 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32* %77)
%79 = getelementptr inbounds [10 x i32], [10 x i32]* %6, i64 0, i64 0
%80 = call i64 @wcscmp(i32* %79, i8* bitcast ([6 x i32]* @.str.10 to i8*))
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %76
store i32 1, i32* %9
br label %83
83: ; preds = %82, %76
%84 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%85 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32* %85)
%87 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%88 = load i32, i32* %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 %88)
%90 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%91 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%92 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%93 = call i32 @wcslen(i32* %92)
%94 = add nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = mul i64 %95, 4
%97 = trunc i64 %96 to i32
%98 = call i32 @wcstombs(i8* %90, i32* %91, i32 %97)
store i32 %98, i32* %2
%99 = load i32, i32* %2
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), i32 %99)
%101 = load i32, i32* %2
%102 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%103 = call i32 @wcslen(i32* %102)
%104 = icmp ne i32 %101, %103
br i1 %104, label %105, label %106
105: ; preds = %83
store i32 1, i32* %9
br label %106
106: ; preds = %105, %83
%107 = getelementptr inbounds [6 x i32], [6 x i32]* %7, i64 0, i64 0
%108 = call i32 @wcslen(i32* %107)
store i32 %108, i32* %2
%109 = load i32, i32* %2
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %109)
%111 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0), i8* %111)
%113 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%114 = call i64 @strcmp(i8* %113, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
%115 = icmp ne i64 %114, 0
br i1 %115, label %116, label %117
116: ; preds = %106
store i32 1, i32* %9
br label %117
117: ; preds = %116, %106
%118 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.18, i64 0, i64 0))
%119 = load i32, i32* %9
ret i32 %119
}

LLVM IR (-O2):
@__const.main.tmp1 = [6 x i32] [i32 87, i32 111, i32 114, i32 108, i32 100, i32 0]
@__const.main.str = [6 x i8] c"Hello\00"
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [13 x i8] c"locale : %s\0A\00"
@.str.2 = [16 x i8] c"MB_CUR_MAX %Zd\0A\00"
@MB_CUR_MAX = global i8* null
@.str.3 = [19 x i8] c"---- test 1 ------\00"
@.str.4 = [31 x i8] c"size of string by mbstowcs %d\0A\00"
@.str.5 = [16 x i8] c"orig string %s\0A\00"
@.str.6 = [21 x i8] c"string by wctomb %s\0A\00"
@.str.7 = [17 x i8] c"string by %%C %C\00"
@.str.8 = [4 x i8] c"%C\0A\00"
@.str.9 = [18 x i8] c"string by %%S %S\0A\00"
@.str.10 = [6 x i32] [i32 72, i32 101, i32 108, i32 108, i32 111, i32 0]
@.str.11 = [19 x i8] c"---- test 2 ------\00"
@.str.12 = [17 x i8] c"wchar string %S\0A\00"
@.str.13 = [10 x i8] c"wchar %C\0A\00"
@.str.14 = [31 x i8] c"size of string by wcstombs %d\0A\00"
@.str.15 = [29 x i8] c"size of string by wcslen %d\0A\00"
@.str.16 = [9 x i8] c"char %s\0A\00"
@.str.17 = [6 x i8] c"World\00"
@.str.18 = [19 x i8] c"------------------\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [10 x i32]
%3 = alloca [6 x i32]
%4 = alloca [6 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = bitcast [10 x i32]* %2 to i8*
%7 = bitcast [6 x i32]* %3 to i8*
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @LC_ALL
%10 = tail call i8* @setlocale(i32 %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** @MB_CUR_MAX
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%16 = call i32 @strlen(i8* %8)
%17 = add nsw i32 %16, 1
%18 = call i32 @mbstowcs(i32* %15, i8* %8, i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @strlen(i8* %8)
%21 = icmp ne i32 %18, %20
%22 = load i32, i32* %15
%23 = call i64 @wctomb(i8* %5, i32 %22)
%24 = shl i64 %23, 32
%25 = ashr exact i64 %24, 32
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %25
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i64 @wctomb(i8* %26, i32 %28)
%30 = add i64 %29, %23
%31 = shl i64 %30, 32
%32 = ashr exact i64 %31, 32
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%36 = load i32, i32* %15
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %15
%39 = icmp ne i32 %38, 72
%40 = load i32, i32* %27
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %27
%43 = icmp ne i32 %42, 101
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i32* %15)
%45 = call i64 @wcscmp(i32* %15, i8* bitcast ([6 x i32]* @.str.10 to i8*))
%46 = icmp ne i64 %45, 0
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i64 0, i64 0))
%48 = getelementptr inbounds [6 x i32], [6 x i32]* %3, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32* %48)
%50 = load i32, i32* %48
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 %50)
%52 = call i32 @wcslen(i32* %48)
%53 = shl i32 %52, 2
%54 = add i32 %53, 4
%55 = call i32 @wcstombs(i8* %5, i32* %48, i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0), i32 %55)
%57 = call i32 @wcslen(i32* %48)
%58 = icmp ne i32 %55, %57
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.15, i64 0, i64 0), i32 %57)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.16, i64 0, i64 0), i8* %5)
%61 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.17, i64 0, i64 0))
%62 = icmp ne i64 %61, 0
%63 = or i1 %58, %62
%64 = select i1 %63, i1 true, i1 %46
%65 = select i1 %64, i1 true, i1 %43
%66 = select i1 %65, i1 true, i1 %39
%67 = select i1 %66, i1 true, i1 %21
%68 = zext i1 %67 to i32
%69 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.18, i64 0, i64 0))
ret i32 %68
}