#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 *, int);
int output_param(char *, int, int, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/);
void dump_string(char *buffer, int *offset) {
  int length = 4;
  int s_size = output_param(buffer, *offset, length, "string size", NULL, 0);
  *offset += length;
  char *temp_string = (char *)malloc(s_size + 1);
  temp_string[s_size] = 0;
  memcpy(temp_string, buffer + *offset, s_size);
  *offset += s_size;
  int left_over = (length + s_size) % 8;
  int padding = 0;
  if (left_over > 0) {
    padding = 8 - left_over;
  }
  *offset += padding;
  free(temp_string);
}


x86 assembly (clang, -O0):
<dump_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    0xe95(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
call   1060 <output_param@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
jle    11f3 <dump_string+0xb3>
mov    $0x8,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rsi),%esi
lea    0xea8(%rip),%rcx
xor    %r13d,%r13d
mov    $0x4,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <output_param@plt>
mov    %eax,%ebx
addl   $0x4,(%r14)
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
movslq %ebx,%rbx
movb   $0x0,(%rax,%rbx,1)
movslq (%r14),%rsi
add    %r12,%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
lea    0x4(%rbx),%eax
lea    0xb(%rbx),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffff8,%ecx
neg    %ecx
lea    (%rbx,%rcx,1),%eax
add    $0x4,%eax
mov    $0x8,%ecx
sub    %eax,%ecx
test   %eax,%eax
cmovle %r13d,%ecx
add    %ebx,%ecx
add    %ecx,(%r14)
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"string size\00"
define void @dump_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 4, i32* %5
%10 = load i8*, i8** %3
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = load i32, i32* %5
%14 = call i32 @output_param(i8* %10, i32 %12, i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
store i32 %14, i32* %6
%15 = load i32, i32* %5
%16 = load i32*, i32** %4
%17 = load i32, i32* %16
%18 = add nsw i32 %17, %15
store i32 %18, i32* %16
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %7
%28 = load i8*, i8** %3
%29 = load i32*, i32** %4
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i32, i32* %6
%34 = call i32 @memcpy(i8* %27, i8* %32, i32 %33)
%35 = load i32, i32* %6
%36 = load i32*, i32** %4
%37 = load i32, i32* %36
%38 = add nsw i32 %37, %35
store i32 %38, i32* %36
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = add nsw i32 %39, %40
%42 = srem i32 %41, 8
store i32 %42, i32* %8
store i32 0, i32* %9
%43 = load i32, i32* %8
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %2
%46 = load i32, i32* %8
%47 = sub nsw i32 8, %46
store i32 %47, i32* %9
br label %48
48: ; preds = %45, %2
%49 = load i32, i32* %9
%50 = load i32*, i32** %4
%51 = load i32, i32* %50
%52 = add nsw i32 %51, %49
store i32 %52, i32* %50
%53 = load i8*, i8** %7
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"string size\00"
define void @dump_string(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @output_param(i8* %0, i32 %3, i32 4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, 4
store i32 %6, i32* %1
%7 = add nsw i32 %4, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = sext i32 %4 to i64
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8 0, i8* %11
%12 = load i32, i32* %1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = tail call i32 @memcpy(i8* %9, i8* %14, i32 %4)
%16 = load i32, i32* %1
%17 = add nsw i32 %4, 4
%18 = srem i32 %17, 8
%19 = icmp sgt i32 %18, 0
%20 = sub nsw i32 8, %18
%21 = select i1 %19, i32 %20, i32 0
%22 = add i32 %21, %4
%23 = add i32 %22, %16
store i32 %23, i32* %1
%24 = tail call i32 @free(i8* %9)
ret void
}