#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 *ksearch(char *, char *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int hadd(char *hplace, const char *keyword) {
  char *v, *v1, *v2, *ve;
  int i, lkey;
  ve = ksearch(hplace, "END");
  if (ve == NULL) {
    return (0);
  }
  v1 = hplace;
  for (v = ve; v >= v1; v = v - 80) {
    v2 = v + 80;
    strncpy(v2, v, 80);
  }
  lkey = (int)strlen(keyword);
  strncpy(hplace, keyword, lkey);
  if (lkey < 8) {
    for (i = lkey; i < 8; i++) {
      hplace[i] = ' ';
    }
    hplace[8] = '=';
  }
  for (i = 9; i < 80; i++) {
    hplace[i] = ' ';
  }
  return (1);
}


x86 assembly (clang, -O0):
<hadd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1050 <ksearch@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    116b <hadd+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1242 <hadd+0x112>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     11b8 <hadd+0x88>
mov    -0x20(%rbp),%rax
add    $0x50,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffb0,%rax
mov    %rax,-0x20(%rbp)
jmp    117b <hadd+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%edx
call   1030 <strncpy@plt>
cmpl   $0x8,-0x40(%rbp)
jge    1210 <hadd+0xe0>
mov    -0x40(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x8,-0x3c(%rbp)
jge    1208 <hadd+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11e4 <hadd+0xb4>
mov    -0x10(%rbp),%rax
movb   $0x3d,0x8(%rax)
movl   $0x9,-0x3c(%rbp)
cmpl   $0x50,-0x3c(%rbp)
jge    123b <hadd+0x10b>
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1217 <hadd+0xe7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hadd>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xebe(%rip),%rsi
call   1060 <ksearch@plt>
test   %rax,%rax
je     11f8 <hadd+0xb8>
mov    %rax,%rbx
cmp    %r15,%rbx
jb     118a <hadd+0x4a>
nopl   0x0(%rax,%rax,1)
lea    0x50(%rbx),%rdi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1030 <strncpy@plt>
add    $0xffffffffffffffb0,%rbx
cmp    %r15,%rbx
jae    1170 <hadd+0x30>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
cmp    $0x7,%ebx
jg     11c8 <hadd+0x88>
movslq %ebx,%rax
lea    (%r15,%rax,1),%rdi
mov    $0x7,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1050 <memset@plt>
movb   $0x3d,0x8(%r15)
movabs $0x2020202020202020,%rax
20 20 20
mov    %rax,0x48(%r15)
movaps 0xe23(%rip),%xmm0
movups %xmm0,0x39(%r15)
movups %xmm0,0x29(%r15)
movups %xmm0,0x19(%r15)
movups %xmm0,0x9(%r15)
mov    $0x1,%eax
jmp    11fa <hadd+0xba>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"END\00"
define i32 @hadd(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = call i8* @ksearch(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store i32 0, i32* %3
br label %72
17: ; preds = %2
%18 = load i8*, i8** %4
store i8* %18, i8** %7
%19 = load i8*, i8** %9
store i8* %19, i8** %6
br label %20
20: ; preds = %30, %17
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = icmp uge i8* %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 80
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i8*, i8** %6
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 80)
br label %30
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 -80
store i8* %32, i8** %6
br label %20
33: ; preds = %20
%34 = load i8*, i8** %5
%35 = call i64 @strlen(i8* %34)
%36 = trunc i64 %35 to i32
store i32 %36, i32* %11
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = load i32, i32* %11
%40 = call i32 @strncpy(i8* %37, i8* %38, i32 %39)
%41 = load i32, i32* %11
%42 = icmp slt i32 %41, 8
br i1 %42, label %43, label %59
43: ; preds = %33
%44 = load i32, i32* %11
store i32 %44, i32* %10
br label %45
45: ; preds = %53, %43
%46 = load i32, i32* %10
%47 = icmp slt i32 %46, 8
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i8*, i8** %4
%50 = load i32, i32* %10
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 32, i8* %52
br label %53
53: ; preds = %48
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
br label %45
56: ; preds = %45
%57 = load i8*, i8** %4
%58 = getelementptr inbounds i8, i8* %57, i64 8
store i8 61, i8* %58
br label %59
59: ; preds = %56, %33
store i32 9, i32* %10
br label %60
60: ; preds = %68, %59
%61 = load i32, i32* %10
%62 = icmp slt i32 %61, 80
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i8*, i8** %4
%65 = load i32, i32* %10
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 32, i8* %67
br label %68
68: ; preds = %63
%69 = load i32, i32* %10
%70 = add nsw i32 %69, 1
store i32 %70, i32* %10
br label %60
71: ; preds = %60
store i32 1, i32* %3
br label %72
72: ; preds = %71, %16
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [4 x i8] c"END\00"
define i32 @hadd(i8* %0, i8* %1) {
%3 = tail call i8* @ksearch(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %28, label %5
5: ; preds = %2
%6 = icmp ult i8* %3, %0
br i1 %6, label %13, label %7
7: ; preds = %5, %7
%8 = phi i8* [ %11, %7 ], [ %3, %5 ]
%9 = getelementptr inbounds i8, i8* %8, i64 80
%10 = tail call i32 @strncpy(i8* %9, i8* %8, i32 80)
%11 = getelementptr inbounds i8, i8* %8, i64 -80
%12 = icmp ult i8* %11, %0
br i1 %12, label %13, label %7
13: ; preds = %7, %5
%14 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%15 = trunc i64 %14 to i32
%16 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %15)
%17 = icmp slt i32 %15, 8
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = shl i64 %14, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr i8, i8* %0, i64 %20
%22 = sub i64 7, %14
%23 = and i64 %22, 4294967295
%24 = add nuw nsw i64 %23, 1
%25 = getelementptr inbounds i8, i8* %0, i64 8
store i8 61, i8* %25
br label %26
26: ; preds = %18, %13
%27 = getelementptr i8, i8* %0, i64 9
br label %28
28: ; preds = %26, %2
%29 = phi i32 [ 0, %2 ], [ 1, %26 ]
ret i32 %29
}