#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 /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ chtype;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(int);
int waddchnstr(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int __darwin_waddchnstr(WINDOW *w, const uint32_t *c, int n) {
  chtype *nc = malloc(sizeof(chtype) * n);
  for (int i = 0; i < n; i++)
    nc[i] = c[i];
  int rv = waddchnstr(w, nc, n);
  free(nc);
  return rv;
}


x86 assembly (clang, -O0):
<__darwin_waddchnstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118d <__darwin_waddchnstr+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115d <__darwin_waddchnstr+0x2d>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <waddchnstr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__darwin_waddchnstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r15
lea    0x0(,%rbx,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    1174 <__darwin_waddchnstr+0x34>
mov    %ebx,%edx
shl    $0x2,%rdx
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <waddchnstr@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @__darwin_waddchnstr(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %7
store i32 0, i32* %8
br label %15
15: ; preds = %29, %3
%16 = load i32, i32* %8
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = load i32*, i32** %7
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
br label %29
29: ; preds = %19
%30 = load i32, i32* %8
%31 = add nsw i32 %30, 1
store i32 %31, i32* %8
br label %15
32: ; preds = %15
%33 = load i32*, i32** %4
%34 = load i32*, i32** %7
%35 = load i32, i32* %6
%36 = call i32 @waddchnstr(i32* %33, i32* %34, i32 %35)
store i32 %36, i32* %9
%37 = load i32*, i32** %7
%38 = call i32 @free(i32* %37)
%39 = load i32, i32* %9
ret i32 %39
}

LLVM IR (-O2):
define i32 @__darwin_waddchnstr(i32* %0, i32* nocapture %1, i32 %2) {
%4 = shl i32 %2, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %1 to i8*
%10 = zext i32 %2 to i64
%11 = shl nuw nsw i64 %10, 2
br label %12
12: ; preds = %7, %3
%13 = tail call i32 @waddchnstr(i32* %0, i32* %5, i32 %2)
%14 = tail call i32 @free(i32* %5)
ret i32 %13
}