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

/* Variables and functions */
int /*<<< orphan*/ LC_CTYPE;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int /*<<< orphan*/ swprintf(char *, int, char *, char *);
int wcslen(char *);
int main(int argc, char *argv[]) {
  wchar_t buf[1024];
  setlocale(LC_CTYPE, "");
  swprintf(buf, 1024, L"%ls", L"HiHi");
  printf("%d wide chars in arg\n", wcslen(L"HiHi"));
  printf("%d wide chars in buf\n", wcslen(buf));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
call   1060 <setlocale@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
lea    0xeab(%rip),%rdx
lea    0xeb4(%rip),%rcx
call   1050 <swprintf@plt>
lea    0xea8(%rip),%rdi
call   1040 <wcslen@plt>
mov    %eax,%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x410(%rbp),%rdi
call   1040 <wcslen@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    0xed3(%rip),%rsi
call   1060 <setlocale@plt>
lea    0xec8(%rip),%rdx
lea    0xed1(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <swprintf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <wcslen@plt>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i32] [i32 37, i32 108, i32 115, i32 0]
@.str.2 = [5 x i32] [i32 72, i32 105, i32 72, i32 105, i32 0]
@.str.3 = [22 x i8] c"%d wide chars in arg\0A\00"
@.str.4 = [22 x i8] c"%d wide chars in buf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @LC_CTYPE
%8 = call i32 @setlocale(i32 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%10 = call i32 @swprintf(i8* %9, i32 1024, i8* bitcast ([4 x i32]* @.str.1 to i8*), i8* bitcast ([5 x i32]* @.str.2 to i8*))
%11 = call i32 @wcslen(i8* bitcast ([5 x i32]* @.str.2 to i8*))
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = call i32 @wcslen(i8* %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %14)
ret i32 0
}

LLVM IR (-O2):
@LC_CTYPE = global i32 0
@.str = [1 x i8] zeroinitializer
@.str.1 = [4 x i32] [i32 37, i32 108, i32 115, i32 0]
@.str.2 = [5 x i32] [i32 72, i32 105, i32 72, i32 105, i32 0]
@.str.3 = [22 x i8] c"%d wide chars in arg\0A\00"
@.str.4 = [22 x i8] c"%d wide chars in buf\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @LC_CTYPE
%6 = tail call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @swprintf(i8* %4, i32 1024, i8* bitcast ([4 x i32]* @.str.1 to i8*), i8* bitcast ([5 x i32]* @.str.2 to i8*))
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 4)
%9 = call i32 @wcslen(i8* %4)
%10 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i32 %9)
ret i32 0
}