#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 PAPI_perror(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void papif_perror(int *code, char *destination_str, int *check,
                  int destination_len) {
  int i;
  char tmp[128];
  *check = PAPI_perror(*code, tmp, 128);
  strncpy(destination_str, tmp, destination_len);
  for (i = strlen(tmp); i < destination_len; destination_str[i++] = ' ')
    ;
}


x86 assembly (clang, -O0):
<papif_perror>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1050 <PAPI_perror@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b7 <papif_perror+0x87>
jmp    119c <papif_perror+0x6c>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    118b <papif_perror+0x5b>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<papif_perror>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    (%rdi),%edi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x80,%edx
call   1060 <PAPI_perror@plt>
mov    %eax,(%r14)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    11a1 <papif_perror+0x61>
movslq %eax,%rcx
add    %rcx,%rbx
not    %eax
add    %ebp,%eax
add    $0x1,%rax
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %rax,%rdx
call   1050 <memset@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @papif_perror(i32* nocapture %0, i8* %1, i32* nocapture writeonly %2, i32 %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %0
%8 = call i32 @PAPI_perror(i32 %7, i8* %6, i32 128)
store i32 %8, i32* %2
%9 = call i32 @strncpy(i8* %1, i8* %6, i32 %3)
%10 = call i32 @strlen(i8* %6)
%11 = icmp slt i32 %10, %3
br i1 %11, label %12, label %19
12: ; preds = %4
%13 = sext i32 %10 to i64
%14 = getelementptr i8, i8* %1, i64 %13
%15 = xor i32 %10, -1
%16 = add i32 %15, %3
%17 = zext i32 %16 to i64
%18 = add nuw nsw i64 %17, 1
br label %19
19: ; preds = %12, %4
ret void
}