#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 */
char *get_uam_names_list();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int snprintf(char *, int, char *, char *, char *);
int afp_status_header(char *text, int *len) {
  int pos;
  memset(text, 0, *len);
  pos = snprintf(text, *len,
                 "AFPFS Version: %s\n"
                 "UAMs compiled in: %s\n",
                 "0.8.1", get_uam_names_list());
  *len -= pos;
  if (*len == 0)
    return -1;
  return pos;
}


x86 assembly (clang, -O0):
<afp_status_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <get_uam_names_list@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    %rax,%r8
lea    0xe86(%rip),%rdx
lea    0xea7(%rip),%rcx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11af <afp_status_header+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b5 <afp_status_header+0x85>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<afp_status_header>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    (%rbx),%ebp
xor    %eax,%eax
call   1050 <get_uam_names_list@plt>
lea    0xead(%rip),%rdx
lea    0xece(%rip),%rcx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rax,%r8
call   1030 <snprintf@plt>
sub    %eax,(%rbx)
mov    $0xffffffff,%ecx
cmove  %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"AFPFS Version: %s\0AUAMs compiled in: %s\0A\00"
@.str.1 = [6 x i8] c"0.8.1\00"
define i32 @afp_status_header(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = load i32*, i32** %5
%9 = load i32, i32* %8
%10 = call i32 @memset(i8* %7, i32 0, i32 %9)
%11 = load i8*, i8** %4
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = call i8* (...) @get_uam_names_list()
%15 = call i32 @snprintf(i8* %11, i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = load i32*, i32** %5
%18 = load i32, i32* %17
%19 = sub nsw i32 %18, %16
store i32 %19, i32* %17
%20 = load i32*, i32** %5
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 -1, i32* %3
br label %26
24: ; preds = %2
%25 = load i32, i32* %6
store i32 %25, i32* %3
br label %26
26: ; preds = %24, %23
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@.str = [40 x i8] c"AFPFS Version: %s\0AUAMs compiled in: %s\0A\00"
@.str.1 = [6 x i8] c"0.8.1\00"
define i32 @afp_status_header(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = tail call i32 @memset(i8* %0, i32 0, i32 %3)
%5 = load i32, i32* %1
%6 = tail call i8* (...) @get_uam_names_list()
%7 = tail call i32 @snprintf(i8* %0, i32 %5, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = load i32, i32* %1
%9 = sub nsw i32 %8, %7
store i32 %9, i32* %1
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 -1, i32 %7
ret i32 %11
}