#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 **calloc(int, int);
int *wcstok(int *, char *, int **);
wchar_t **wsplitlines(wchar_t *wbuffer, int *linecount) {
  if (!wbuffer)
    return NULL;
  int nlcount = 1;
  wchar_t *wbufpos = wbuffer;
  while (*wbufpos != L'\0') {
    if (*wbufpos == L'\n')
      nlcount++;
    wbufpos++;
  }
  nlcount--;
  wchar_t *__wstate = NULL;
  wchar_t **lines = calloc(nlcount, sizeof(wchar_t *));
  lines[0] = wcstok(wbuffer, L"\n", &__wstate);
  for (int i = 1; i < nlcount; i++) {
    lines[i] = wcstok(NULL, L"\n", &__wstate);
  }
  if (linecount)
    *linecount = nlcount;
  return lines;
}


x86 assembly (clang, -O0):
<wsplitlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1148 <wsplitlines+0x28>
movq   $0x0,-0x8(%rbp)
jmp    122b <wsplitlines+0x10b>
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
je     118b <wsplitlines+0x6b>
mov    -0x28(%rbp),%rax
cmpl   $0xa,(%rax)
jne    117a <wsplitlines+0x5a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
jmp    1157 <wsplitlines+0x37>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <wcstok@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120f <wsplitlines+0xef>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe17(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <wcstok@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d2 <wsplitlines+0xb2>
cmpq   $0x0,-0x18(%rbp)
je     1223 <wsplitlines+0x103>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wsplitlines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     11e9 <wsplitlines+0xc9>
mov    %rdi,%r12
mov    $0x1,%ebp
mov    %rdi,%rax
jmp    1157 <wsplitlines+0x37>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
add    $0x4,%rax
mov    (%rax),%ecx
cmp    $0xa,%ecx
je     1150 <wsplitlines+0x30>
test   %ecx,%ecx
jne    1153 <wsplitlines+0x33>
mov    %rsi,0x10(%rsp)
lea    -0x1(%rbp),%r15d
movq   $0x0,0x8(%rsp)
mov    %r15d,%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%rbx
lea    0xe75(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r12,%rdi
call   1040 <wcstok@plt>
mov    %rax,(%rbx)
cmp    $0x3,%ebp
jl     11da <wsplitlines+0xba>
mov    %r15d,%ebp
mov    $0x1,%r14d
lea    0xe50(%rip),%r12
lea    0x8(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1040 <wcstok@plt>
mov    %rax,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%rbp
jne    11c0 <wsplitlines+0xa0>
mov    0x10(%rsp),%rax
test   %rax,%rax
je     11eb <wsplitlines+0xcb>
mov    %r15d,(%rax)
jmp    11eb <wsplitlines+0xcb>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i32] [i32 10, i32 0]
define i32** @wsplitlines(i32* %0, i32* %1) {
%3 = alloca i32**
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32**
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %2
store i32** null, i32*** %3
br label %60
14: ; preds = %2
store i32 1, i32* %6
%15 = load i32*, i32** %4
store i32* %15, i32** %7
br label %16
16: ; preds = %27, %14
%17 = load i32*, i32** %7
%18 = load i32, i32* %17
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %16
%21 = load i32*, i32** %7
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %27
27: ; preds = %24, %20
%28 = load i32*, i32** %7
%29 = getelementptr inbounds i32, i32* %28, i32 1
store i32* %29, i32** %7
br label %16
30: ; preds = %16
%31 = load i32, i32* %6
%32 = add nsw i32 %31, -1
store i32 %32, i32* %6
store i32* null, i32** %8
%33 = load i32, i32* %6
%34 = call i32** @calloc(i32 %33, i32 8)
store i32** %34, i32*** %9
%35 = load i32*, i32** %4
%36 = call i32* @wcstok(i32* %35, i8* bitcast ([2 x i32]* @.str to i8*), i32** %8)
%37 = load i32**, i32*** %9
%38 = getelementptr inbounds i32*, i32** %37, i64 0
store i32* %36, i32** %38
store i32 1, i32* %10
br label %39
39: ; preds = %49, %30
%40 = load i32, i32* %10
%41 = load i32, i32* %6
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %52
43: ; preds = %39
%44 = call i32* @wcstok(i32* null, i8* bitcast ([2 x i32]* @.str to i8*), i32** %8)
%45 = load i32**, i32*** %9
%46 = load i32, i32* %10
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32*, i32** %45, i64 %47
store i32* %44, i32** %48
br label %49
49: ; preds = %43
%50 = load i32, i32* %10
%51 = add nsw i32 %50, 1
store i32 %51, i32* %10
br label %39
52: ; preds = %39
%53 = load i32*, i32** %5
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %52
%56 = load i32, i32* %6
%57 = load i32*, i32** %5
store i32 %56, i32* %57
br label %58
58: ; preds = %55, %52
%59 = load i32**, i32*** %9
store i32** %59, i32*** %3
br label %60
60: ; preds = %58, %13
%61 = load i32**, i32*** %3
ret i32** %61
}

LLVM IR (-O2):
@.str = [2 x i32] [i32 10, i32 0]
define noalias i32** @wsplitlines(i32* %0, i32* writeonly %1) {
%3 = alloca i32*
%4 = icmp eq i32* %0, null
br i1 %4, label %32, label %5
5: ; preds = %2, %11
%6 = phi i32 [ %12, %11 ], [ 1, %2 ]
%7 = phi i32* [ %13, %11 ], [ %0, %2 ]
%8 = load i32, i32* %7
switch i32 %8, label %11 [
i32 0, label %14
i32 10, label %9
]
9: ; preds = %5
%10 = add nsw i32 %6, 1
br label %11
11: ; preds = %5, %9
%12 = phi i32 [ %10, %9 ], [ %6, %5 ]
%13 = getelementptr inbounds i32, i32* %7, i64 1
br label %5
14: ; preds = %5
%15 = add nsw i32 %6, -1
%16 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%17 = tail call i32** @calloc(i32 %15, i32 8)
%18 = call i32* @wcstok(i32* %0, i8* bitcast ([2 x i32]* @.str to i8*), i32** %3)
store i32* %18, i32** %17
%19 = icmp sgt i32 %6, 2
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = zext i32 %15 to i64
br label %24
22: ; preds = %24, %14
%23 = icmp eq i32* %1, null
br i1 %23, label %31, label %30
24: ; preds = %20, %24
%25 = phi i64 [ 1, %20 ], [ %28, %24 ]
%26 = call i32* @wcstok(i32* null, i8* bitcast ([2 x i32]* @.str to i8*), i32** %3)
%27 = getelementptr inbounds i32*, i32** %17, i64 %25
store i32* %26, i32** %27
%28 = add nuw nsw i64 %25, 1
%29 = icmp eq i64 %28, %21
br i1 %29, label %22, label %24
30: ; preds = %22
store i32 %15, i32* %1
br label %31
31: ; preds = %30, %22
br label %32
32: ; preds = %2, %31
%33 = phi i32** [ %17, %31 ], [ null, %2 ]
ret i32** %33
}