#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 *);
int /*<<< orphan*/ mputchar(int /*<<< orphan*/);
int /*<<< orphan*/ mputuleb128(unsigned long);
unsigned long strlen(char *);
void mputstring(char *string) {
  unsigned long len = strlen(string);
  char *p = string;
  unsigned long i = 0;
  mputuleb128(len);
  while (i++ < len)
    mputchar(*p++);
  free(string);
}


x86 assembly (clang, -O0):
<mputstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <mputuleb128@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
jae    11a7 <mputstring+0x67>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1050 <mputchar@plt>
jmp    1172 <mputstring+0x32>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mputstring>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <mputuleb128@plt>
test   %r15,%r15
je     1173 <mputstring+0x33>
xor    %ebx,%ebx
nop
movsbl (%r14,%rbx,1),%edi
add    $0x1,%rbx
call   1050 <mputchar@plt>
cmp    %rbx,%r15
jne    1160 <mputstring+0x20>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @mputstring(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %3
%8 = load i8*, i8** %2
store i8* %8, i8** %4
store i64 0, i64* %5
%9 = load i64, i64* %3
%10 = call i32 @mputuleb128(i64 %9)
br label %11
11: ; preds = %16, %1
%12 = load i64, i64* %5
%13 = add i64 %12, 1
store i64 %13, i64* %5
%14 = load i64, i64* %3
%15 = icmp ult i64 %12, %14
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
%19 = load i8, i8* %17
%20 = sext i8 %19 to i32
%21 = call i32 @mputchar(i32 %20)
br label %11
22: ; preds = %11
%23 = load i8*, i8** %2
%24 = call i32 @free(i8* %23)
ret void
}

LLVM IR (-O2):
define void @mputstring(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i32 @mputuleb128(i64 %2)
%4 = icmp eq i64 %2, 0
br i1 %4, label %14, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %8, %5 ], [ 0, %1 ]
%7 = phi i8* [ %9, %5 ], [ %0, %1 ]
%8 = add nuw i64 %6, 1
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = load i8, i8* %7
%11 = sext i8 %10 to i32
%12 = tail call i32 @mputchar(i32 %11)
%13 = icmp eq i64 %8, %2
br i1 %13, label %14, label %5
14: ; preds = %5, %1
%15 = tail call i32 @free(i8* %0)
ret void
}