#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 */

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
void split(char *x, int n, char **a, char **b) {
  *a = calloc(n / 2 + 1, sizeof(char));
  *b = calloc(n - n / 2 + 1, sizeof(char));
  memcpy(*a, x, n / 2);
  memcpy(*b, x + n / 2, n - n / 2);
  (*a)[n / 2] = 0;
  (*b)[n - n / 2] = 0;
}


x86 assembly (clang, -O0):
<split>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%edi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    %eax,%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cltq
add    %rax,%rsi
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x34(%rbp),%edx
sub    %eax,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%eax
mov    $0x2,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x28(%rbp),%rax
sub    %edx,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%r12
mov    %esi,%ebx
shr    $0x1f,%ebx
add    %esi,%ebx
sar    %ebx
lea    0x1(%rbx),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,(%r15)
sub    %ebx,%r13d
lea    0x1(%r13),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,(%r14)
mov    (%r15),%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    (%r14),%rdi
movslq %ebx,%rbx
add    %rbx,%r12
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbx,1)
mov    (%r14),%rax
movslq %r13d,%rcx
movb   $0x0,(%rax,%rcx,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @split(i8* %0, i32 %1, i8** %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8**
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i8** %3, i8*** %8
%9 = load i32, i32* %6
%10 = sdiv i32 %9, 2
%11 = add nsw i32 %10, 1
%12 = call i8* @calloc(i32 %11, i32 1)
%13 = load i8**, i8*** %7
store i8* %12, i8** %13
%14 = load i32, i32* %6
%15 = load i32, i32* %6
%16 = sdiv i32 %15, 2
%17 = sub nsw i32 %14, %16
%18 = add nsw i32 %17, 1
%19 = call i8* @calloc(i32 %18, i32 1)
%20 = load i8**, i8*** %8
store i8* %19, i8** %20
%21 = load i8**, i8*** %7
%22 = load i8*, i8** %21
%23 = load i8*, i8** %5
%24 = load i32, i32* %6
%25 = sdiv i32 %24, 2
%26 = call i32 @memcpy(i8* %22, i8* %23, i32 %25)
%27 = load i8**, i8*** %8
%28 = load i8*, i8** %27
%29 = load i8*, i8** %5
%30 = load i32, i32* %6
%31 = sdiv i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i32, i32* %6
%35 = load i32, i32* %6
%36 = sdiv i32 %35, 2
%37 = sub nsw i32 %34, %36
%38 = call i32 @memcpy(i8* %28, i8* %33, i32 %37)
%39 = load i8**, i8*** %7
%40 = load i8*, i8** %39
%41 = load i32, i32* %6
%42 = sdiv i32 %41, 2
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
store i8 0, i8* %44
%45 = load i8**, i8*** %8
%46 = load i8*, i8** %45
%47 = load i32, i32* %6
%48 = load i32, i32* %6
%49 = sdiv i32 %48, 2
%50 = sub nsw i32 %47, %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %46, i64 %51
store i8 0, i8* %52
ret void
}

LLVM IR (-O2):
define void @split(i8* %0, i32 %1, i8** nocapture %2, i8** nocapture %3) {
%5 = sdiv i32 %1, 2
%6 = add nsw i32 %5, 1
%7 = tail call i8* @calloc(i32 %6, i32 1)
store i8* %7, i8** %2
%8 = sub nsw i32 %1, %5
%9 = add nsw i32 %8, 1
%10 = tail call i8* @calloc(i32 %9, i32 1)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = tail call i32 @memcpy(i8* %11, i8* %0, i32 %5)
%13 = load i8*, i8** %3
%14 = sext i32 %5 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 @memcpy(i8* %13, i8* %15, i32 %8)
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 %14
store i8 0, i8* %18
%19 = load i8*, i8** %3
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8 0, i8* %21
ret void
}