#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 hputc(char *, char const *, char const *);
scalar_t__ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int hputs(char *hstring, const char *keyword, const char *cval) {
  char squot = 39;
  char value[80];
  int lcval, i, lkeyword;
  lkeyword = (int)strlen(keyword);
  if (lkeyword == 7 && (strncmp(keyword, "COMMENT", 7) == 0 ||
                        strncmp(keyword, "HISTORY", 7) == 0)) {
    return (hputc(hstring, keyword, cval));
  }
  lcval = (int)strlen(cval);
  if (lcval > 67) {
    lcval = 67;
  }
  value[0] = squot;
  strncpy(&value[1], cval, lcval);
  if (lcval < 8) {
    for (i = lcval; i < 8; i++) {
      value[i + 1] = ' ';
    }
    lcval = 8;
  }
  value[lcval + 1] = squot;
  value[lcval + 2] = (char)0;
  return (hputc(hstring, keyword, value));
}


x86 assembly (clang, -O0):
<hputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movb   $0x27,-0x21(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0x7,-0x8c(%rbp)
jne    11ce <hputs+0x8e>
mov    -0x18(%rbp),%rdi
lea    0xe7e(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11b5 <hputs+0x75>
mov    -0x18(%rbp),%rdi
lea    0xe67(%rip),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11ce <hputs+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <hputc@plt>
mov    %eax,-0x4(%rbp)
jmp    129b <hputs+0x15b>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x43,-0x84(%rbp)
jle    11f4 <hputs+0xb4>
movl   $0x43,-0x84(%rbp)
mov    -0x21(%rbp),%al
mov    %al,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1030 <strncpy@plt>
cmpl   $0x8,-0x84(%rbp)
jge    1265 <hputs+0x125>
mov    -0x84(%rbp),%eax
mov    %eax,-0x88(%rbp)
cmpl   $0x8,-0x88(%rbp)
jge    125b <hputs+0x11b>
mov    -0x88(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x20,-0x80(%rbp,%rax,1)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    122a <hputs+0xea>
movl   $0x8,-0x84(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x84(%rbp),%eax
add    $0x1,%eax
cltq
mov    %cl,-0x80(%rbp,%rax,1)
mov    -0x84(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1060 <hputc@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hputs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <strlen@plt>
cmp    $0x7,%eax
jne    11a8 <hputs+0x58>
lea    0xe87(%rip),%rsi
mov    %r15,%rdi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1227 <hputs+0xd7>
lea    0xe72(%rip),%rsi
mov    %r15,%rdi
mov    $0x7,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1227 <hputs+0xd7>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
cmp    $0x43,%ebx
mov    $0x43,%ebp
cmovl  %ebx,%ebp
movb   $0x27,(%rsp)
lea    0x1(%rsp),%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
cmp    $0x7,%ebp
jg     1203 <hputs+0xb3>
mov    $0x8,%ebp
cmp    $0x7,%ebx
jg     1203 <hputs+0xb3>
movslq %ebx,%rax
mov    %rsp,%rcx
lea    (%rax,%rcx,1),%rdi
add    $0x1,%rdi
mov    $0x7,%edx
sub    %eax,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1060 <memset@plt>
mov    %ebp,%eax
mov    %rsp,%rdx
movw   $0x27,0x1(%rax,%rdx,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <hputc@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <hputc@plt>

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

LLVM IR (-O2):
@.str = [8 x i8] c"COMMENT\00"
@.str.1 = [8 x i8] c"HISTORY\00"
define i32 @hputs(i8* %0, i8* %1, i8* %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = trunc i64 %6 to i32
%8 = icmp eq i32 %7, 7
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12, %9
%16 = tail call i32 @hputc(i8* %0, i8* %1, i8* %2)
br label %44
17: ; preds = %12, %3
%18 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%19 = trunc i64 %18 to i32
%20 = icmp slt i32 %19, 67
%21 = select i1 %20, i32 %19, i32 67
store i8 39, i8* %5
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 1
%23 = call i32 @strncpy(i8* %22, i8* %2, i32 %21)
%24 = icmp slt i32 %21, 8
br i1 %24, label %25, label %35
25: ; preds = %17
%26 = icmp slt i32 %19, 8
br i1 %26, label %27, label %35
27: ; preds = %25
%28 = shl i64 %18, 32
%29 = ashr exact i64 %28, 32
%30 = add nsw i64 %29, 1
%31 = getelementptr [80 x i8], [80 x i8]* %4, i64 0, i64 %30
%32 = sub i64 7, %18
%33 = and i64 %32, 4294967295
%34 = add nuw nsw i64 %33, 1
br label %35
35: ; preds = %27, %25, %17
%36 = phi i32 [ %21, %17 ], [ 8, %25 ], [ 8, %27 ]
%37 = add nuw nsw i32 %36, 1
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %38
store i8 39, i8* %39
%40 = add nuw nsw i32 %36, 2
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %41
store i8 0, i8* %42
%43 = call i32 @hputc(i8* %0, i8* %1, i8* %5)
br label %44
44: ; preds = %35, %15
%45 = phi i32 [ %16, %15 ], [ %43, %35 ]
ret i32 %45
}