#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*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *getPES(char *dst, int size, char *entry) {
  char *ret = dst;
  strncpy(ret, entry, size);
  int i, max = (size - strlen(ret)) / 3;
  for (i = 0; i < max; i++) {
    if (strlen(ret) > 0) {
      strcat(ret, " 00");
    } else {
      strcat(ret, "00");
    }
  }
  return dst;
}


x86 assembly (clang, -O0):
<getPES>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
sub    %ecx,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11d9 <getPES+0xa9>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    11b6 <getPES+0x86>
mov    -0x20(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1050 <strcat@plt>
jmp    11c6 <getPES+0x96>
mov    -0x20(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1050 <strcat@plt>
jmp    11cb <getPES+0x9b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1183 <getPES+0x53>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPES>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rdx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
cmp    $0x3,%ebp
jl     119e <getPES+0x6e>
movslq %ebp,%rax
imul   $0x55555556,%rax,%rbp
mov    %rbp,%rax
shr    $0x3f,%rax
shr    $0x20,%rbp
add    %eax,%ebp
lea    0xe8d(%rip),%r14
lea    0xe87(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
mov    %r15,%rsi
cmovg  %r14,%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
add    $0xffffffff,%ebp
jne    1180 <getPES+0x50>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" 00\00"
@.str.1 = [3 x i8] c"00\00"
define i8* @getPES(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %6
%13 = load i32, i32* %5
%14 = call i32 @strncpy(i8* %11, i8* %12, i32 %13)
%15 = load i32, i32* %5
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
%18 = sub nsw i32 %15, %17
%19 = sdiv i32 %18, 3
store i32 %19, i32* %9
store i32 0, i32* %8
br label %20
20: ; preds = %35, %3
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %38
24: ; preds = %20
%25 = load i8*, i8** %7
%26 = call i32 @strlen(i8* %25)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i8*, i8** %7
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %34
31: ; preds = %24
%32 = load i8*, i8** %7
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %20
38: ; preds = %20
%39 = load i8*, i8** %4
ret i8* %39
}

LLVM IR (-O2):
@.str = [4 x i8] c" 00\00"
@.str.1 = [3 x i8] c"00\00"
define i8* @getPES(i8* returned %0, i32 %1, i8* %2) {
%4 = tail call i32 @strncpy(i8* %0, i8* %2, i32 %1)
%5 = tail call i32 @strlen(i8* %0)
%6 = sub nsw i32 %1, %5
%7 = sdiv i32 %6, 3
%8 = icmp sgt i32 %6, 2
br i1 %8, label %9, label %17
9: ; preds = %3, %9
%10 = phi i32 [ %15, %9 ], [ 0, %3 ]
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%14 = tail call i32 @strcat(i8* %0, i8* %13)
%15 = add nuw nsw i32 %10, 1
%16 = icmp eq i32 %15, %7
br i1 %16, label %17, label %9
17: ; preds = %9, %3
ret i8* %0
}