#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*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
bool putstr(char **out, size_t *outlen, const char *in) {
  size_t inlen = strlen(in);
  if (inlen >= *outlen)
    return false;
  memcpy(*out, in, inlen + 1);
  *out += inlen;
  *outlen -= inlen;
  return true;
}


x86 assembly (clang, -O0):
<putstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jb     115e <putstr+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    119c <putstr+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
xor    %eax,%eax
cmp    (%r15),%rbx
jae    1160 <putstr+0x40>
mov    (%r14),%rdi
mov    %rbx,%rdx
add    $0x1,%rdx
mov    %r12,%rsi
call   1040 <memcpy@plt>
add    %rbx,(%r14)
sub    %rbx,(%r15)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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