#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*/ printf(char *);
int snprintf(char *, int, char const *);
void print_msg(char *buf, int buflen, const char *msg) {
  int l = snprintf(buf, buflen, msg);
  char *pc = buf + l;
  while (--l >= 0)
    *pc++ = ' ';
  *pc++ = '\n';
  *pc = '\0';
  printf(buf);
}


x86 assembly (clang, -O0):
<print_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jl     117e <print_msg+0x5e>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x20,(%rax)
jmp    1155 <print_msg+0x35>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0xa,(%rax)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_msg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <snprintf@plt>
movslq %eax,%rbx
lea    (%r14,%rbx,1),%rdi
test   %ebx,%ebx
jle    1161 <print_msg+0x31>
mov    %ebx,%edx
mov    $0x20,%esi
call   1050 <memset@plt>
lea    -0x1(%rbx),%eax
add    %rbx,%rax
lea    (%r14,%rax,1),%rdi
add    $0x1,%rdi
movw   $0xa,(%rdi)
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
define void @print_msg(i8* %0, i32 %1, i8* %2) {
%4 = tail call i32 @snprintf(i8* %0, i32 %1, i8* %2)
%5 = sext i32 %4 to i64
%6 = getelementptr i8, i8* %0, i64 %5
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %15
8: ; preds = %3
%9 = zext i32 %4 to i64
%10 = add nsw i32 %4, -1
%11 = zext i32 %10 to i64
%12 = add nsw i64 %5, %11
%13 = add nsw i64 %12, 1
%14 = getelementptr i8, i8* %0, i64 %13
br label %15
15: ; preds = %8, %3
%16 = phi i8* [ %6, %3 ], [ %14, %8 ]
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8 10, i8* %16
store i8 0, i8* %17
%18 = tail call i32 @printf(i8* dereferenceable(1) %0)
ret void
}