#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);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
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, (size_t)destination_len);
  for (i = (int)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
movslq -0x1c(%rbp),%rdx
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    11b8 <papif_perror+0x88>
jmp    119d <papif_perror+0x6d>
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    118c <papif_perror+0x5c>
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,%r14d
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    (%rdi),%edi
mov    %rsp,%r15
mov    %r15,%rsi
mov    $0x80,%edx
call   1060 <PAPI_perror@plt>
mov    %eax,0x0(%rbp)
movslq %r14d,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jge    11a7 <papif_perror+0x67>
movslq %eax,%rcx
add    %rcx,%rbx
not    %eax
add    %r14d,%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 = sext i32 %18 to i64
%20 = call i32 @strncpy(i8* %16, i8* %17, i64 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
store i32 %23, i32* %9
br label %24
24: ; preds = %29, %4
%25 = load i32, i32* %9
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24
br label %29
29: ; preds = %28
%30 = load i8*, i8** %6
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 32, i8* %34
br label %24
35: ; preds = %24
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 = sext i32 %3 to i64
%10 = call i32 @strncpy(i8* %1, i8* %6, i64 %9)
%11 = call i64 @strlen(i8* %6)
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %12, %3
br i1 %13, label %14, label %22
14: ; preds = %4
%15 = shl i64 %11, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr i8, i8* %1, i64 %16
%18 = xor i32 %12, -1
%19 = add i32 %18, %3
%20 = zext i32 %19 to i64
%21 = add nuw nsw i64 %20, 1
br label %22
22: ; preds = %14, %4
ret void
}