#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*/ mbstowcs(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ wcstombs(char *, char *, int);
int main(void) {
  char *str = "Hi!±z¦n";
  wchar_t wstr[10];
  char str2[10];
  mbstowcs(wstr, str, 10);
  printf("%s\n", str);
  printf("%ls\n", wstr);
  wcstombs(str2, wstr, 10);
  printf("%s", str2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x12(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0xa,%edx
call   1030 <mbstowcs@plt>
mov    -0x8(%rbp),%rsi
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    -0x12(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x1c(%rbp),%rdi
lea    -0x12(%rbp),%rsi
mov    $0xa,%edx
call   1050 <wcstombs@plt>
lea    -0x1c(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xec0(%rip),%r14
lea    0x16(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1030 <mbstowcs@plt>
lea    0xeae(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
call   1050 <wcstombs@plt>
lea    0xe84(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Hi!\C2\B1z\C2\A6n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"%ls\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = load i8*, i8** %1
%6 = call i32 @mbstowcs(i8* %4, i8* %5, i32 10)
%7 = load i8*, i8** %1
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%10 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%13 = call i32 @wcstombs(i8* %11, i8* %12, i32 10)
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Hi!\C2\B1z\C2\A6n\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [5 x i8] c"%ls\0A\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = call i32 @mbstowcs(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 10)
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%8 = call i32 @wcstombs(i8* %4, i8* %3, i32 10)
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
ret i32 0
}