#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 */
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int catvars(char *buf1, char *buf2, unsigned int len1, unsigned int len2) {
  char *mybuf;
  mybuf = (char *)malloc(sizeof(char) * 256);
  if ((len1 + len2) > 256) {
    return -1;
  }
  memcpy(mybuf, buf1, len1);
  memcpy(mybuf + len1, buf2, len2);
  free(mybuf);
  return 0;
}


x86 assembly (clang, -O0):
<catvars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0x100,%eax
jbe    1171 <catvars+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <catvars+0x77>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catvars>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r13
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    (%r15,%rbx,1),%ecx
mov    $0xffffffff,%eax
cmp    $0x100,%ecx
ja     1189 <catvars+0x59>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    %ebx,%edi
add    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @catvars(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = call i64 @malloc(i32 256)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %10
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = add i32 %13, %14
%16 = icmp ugt i32 %15, 256
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %32
18: ; preds = %4
%19 = load i8*, i8** %10
%20 = load i8*, i8** %6
%21 = load i32, i32* %8
%22 = call i32 @memcpy(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %10
%24 = load i32, i32* %8
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8*, i8** %7
%28 = load i32, i32* %9
%29 = call i32 @memcpy(i8* %26, i8* %27, i32 %28)
%30 = load i8*, i8** %10
%31 = call i32 @free(i8* %30)
store i32 0, i32* %5
br label %32
32: ; preds = %18, %17
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
define i32 @catvars(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i64 @malloc(i32 256)
%6 = inttoptr i64 %5 to i8*
%7 = add i32 %3, %2
%8 = icmp ugt i32 %7, 256
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = tail call i32 @memcpy(i8* %6, i8* %0, i32 %2)
%11 = zext i32 %2 to i64
%12 = getelementptr inbounds i8, i8* %6, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %1, i32 %3)
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %4, %9
%16 = phi i32 [ 0, %9 ], [ -1, %4 ]
ret i32 %16
}