#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
int genMSG_ret(uint8_t *buffer, uint32_t *len, int success, const char *hint) {
  if (success == 1)
    sprintf((char *)buffer, "success\\");
  else
    sprintf((char *)buffer, "failed\\");
  if (hint != NULL)
    sprintf((char *)(buffer + strlen((char *)buffer)), "%s\\", hint);
  *len = strlen((char *)buffer);
  return 0;
}


x86 assembly (clang, -O0):
<genMSG_ret>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1158 <genMSG_ret+0x38>
mov    -0x8(%rbp),%rdi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    116a <genMSG_ret+0x4a>
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
cmpq   $0x0,-0x20(%rbp)
je     11a5 <genMSG_ret+0x85>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genMSG_ret>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
cmp    $0x1,%edx
jne    114b <genMSG_ret+0x2b>
movabs $0x5c73736563637573,%rax
73 73 5c
mov    %rax,(%rbx)
movb   $0x0,0x8(%rbx)
test   %r15,%r15
jne    115d <genMSG_ret+0x3d>
jmp    117c <genMSG_ret+0x5c>
movabs $0x5c64656c696166,%rax
mov    %rax,(%rbx)
test   %r15,%r15
je     117c <genMSG_ret+0x5c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,4),%rdi
lea    0xe97(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"success\\\00"
@.str.1 = [8 x i8] c"failed\\\00"
@.str.2 = [4 x i8] c"%s\\\00"
define i32 @genMSG_ret(i32* %0, i32* %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%9 = load i32, i32* %7
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = load i32*, i32** %5
%13 = bitcast i32* %12 to i8*
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
br label %19
15: ; preds = %4
%16 = load i32*, i32** %5
%17 = bitcast i32* %16 to i8*
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %15, %11
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = load i32*, i32** %5
%24 = load i32*, i32** %5
%25 = bitcast i32* %24 to i8*
%26 = call i32 @strlen(i8* %25)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %23, i64 %27
%29 = bitcast i32* %28 to i8*
%30 = load i8*, i8** %8
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %22, %19
%33 = load i32*, i32** %5
%34 = bitcast i32* %33 to i8*
%35 = call i32 @strlen(i8* %34)
%36 = load i32*, i32** %6
store i32 %35, i32* %36
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"success\\\00"
@.str.2 = [4 x i8] c"%s\\\00"
define i32 @genMSG_ret(i32* %0, i32* nocapture writeonly %1, i32 %2, i8* %3) {
%5 = icmp eq i32 %2, 1
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = bitcast i32* %0 to i8*
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(9) %7, i8* align 1 dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 9, i1 false)
br label %10
8: ; preds = %4
%9 = bitcast i32* %0 to i64*
store i64 26006084630700390, i64* %9
br label %10
10: ; preds = %8, %6
%11 = icmp eq i8* %3, null
br i1 %11, label %19, label %12
12: ; preds = %10
%13 = bitcast i32* %0 to i8*
%14 = tail call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = bitcast i32* %16 to i8*
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %17, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %19
19: ; preds = %10, %12
%20 = bitcast i32* %0 to i8*
%21 = tail call i32 @strlen(i8* %20)
store i32 %21, i32* %1
ret i32 0
}