#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*/ strcpy(char *, char *);
int unbit_magic_buf(char *what, size_t len, char **buffer, size_t *buflen) {
  if (len >= *buflen - 1)
    return -1;
  strcpy(*buffer, what);
  *buflen -= len + 1;
  *buffer += len + 1;
  return 0;
}


x86 assembly (clang, -O0):
<unbit_magic_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jb     114c <unbit_magic_buf+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <unbit_magic_buf+0x7a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x20(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unbit_magic_buf>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rsi,%rbx
mov    (%rcx),%rcx
add    $0xffffffffffffffff,%rcx
mov    $0xffffffff,%eax
cmp    %rsi,%rcx
jbe    1146 <unbit_magic_buf+0x36>
mov    %rdx,%r14
mov    %rdi,%rsi
mov    (%rdx),%rdi
call   1030 <strcpy@plt>
add    $0x1,%rbx
sub    %rbx,(%r15)
add    %rbx,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @unbit_magic_buf(i8* %0, i64 %1, i8** nocapture %2, i64* nocapture %3) {
%5 = load i64, i64* %3
%6 = add i64 %5, -1
%7 = icmp ugt i64 %6, %1
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = tail call i32 @strcpy(i8* %9, i8* %0)
%11 = add nuw i64 %1, 1
%12 = load i64, i64* %3
%13 = sub i64 %12, %11
store i64 %13, i64* %3
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 %11
store i8* %15, i8** %2
br label %16
16: ; preds = %4, %8
%17 = phi i32 [ 0, %8 ], [ -1, %4 ]
ret i32 %17
}