#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 */
struct icom {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ imadd_fits(struct icom *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int strlen(char *);
void imaddhist(struct icom *comp, char *s) {
  char line[81];
  int i, l;
  char head[10];
  l = strlen(s);
  sprintf(head, "HISTORY");
  for (i = 0; i <= l / 70; i++) {
    (void)sprintf(line, "%s  %-70.70s", head, s + i * 70);
    imadd_fits(comp, line);
    sprintf(head, "HISTORY ");
  }
}


x86 assembly (clang, -O0):
<imaddhist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x78(%rbp)
lea    -0x82(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x88(%rbp)
mov    -0x78(%rbp),%eax
mov    $0x46,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x88(%rbp),%eax
cmp    %ecx,%eax
jg     11e5 <imaddhist+0xb5>
lea    -0x70(%rbp),%rdi
lea    -0x82(%rbp),%rdx
mov    -0x10(%rbp),%rcx
imul   $0x46,-0x74(%rbp),%eax
cltq
add    %rax,%rcx
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1030 <imadd_fits@plt>
lea    -0x82(%rbp),%rdi
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    116b <imaddhist+0x3b>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<imaddhist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
movabs $0x59524f54534948,%rcx
mov    %rcx,(%rsp)
cmp    $0xffffffbb,%eax
jl     11c5 <imaddhist+0x95>
movslq %eax,%rcx
imul   $0xffffffffea0ea0eb,%rcx,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%eax
sar    $0x6,%eax
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0x1,%ebp
lea    0x10(%rsp),%r12
mov    %rsp,%r13
movabs $0x2059524f54534948,%r15
52 59 20
nop
mov    %r12,%rdi
lea    0xe66(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <imadd_fits@plt>
mov    %r15,(%rsp)
movb   $0x0,0x8(%rsp)
add    $0x46,%rbx
add    $0xffffffffffffffff,%rbp
jne    1190 <imaddhist+0x60>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.icom = type { i32 }
@.str = [8 x i8] c"HISTORY\00"
@.str.1 = [13 x i8] c"%s %-70.70s\00"
@.str.2 = [9 x i8] c"HISTORY \00"
define void @imaddhist(%struct.icom* %0, i8* %1) {
%3 = alloca %struct.icom*
%4 = alloca i8*
%5 = alloca [81 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
store %struct.icom* %0, %struct.icom** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %7
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %13
13: ; preds = %32, %2
%14 = load i32, i32* %6
%15 = load i32, i32* %7
%16 = sdiv i32 %15, 70
%17 = icmp sle i32 %14, %16
br i1 %17, label %18, label %35
18: ; preds = %13
%19 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = mul nsw i32 %22, 70
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %25)
%27 = load %struct.icom*, %struct.icom** %3
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%29 = call i32 @imadd_fits(%struct.icom* %27, i8* %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %18
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %13
35: ; preds = %13
ret void
}

LLVM IR (-O2):
%struct.icom = type { i32 }
@.str.1 = [13 x i8] c"%s %-70.70s\00"
@.str.2 = [9 x i8] c"HISTORY \00"
define void @imaddhist(%struct.icom* %0, i8* %1) {
%3 = alloca [81 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %1)
%8 = bitcast [10 x i8]* %4 to i64*
store i64 25141773597886792, i64* %8
%9 = icmp slt i32 %7, -69
br i1 %9, label %22, label %10
10: ; preds = %2
%11 = sdiv i32 %7, 70
%12 = add nuw nsw i32 %11, 1
%13 = zext i32 %12 to i64
br label %14
14: ; preds = %10, %14
%15 = phi i64 [ 0, %10 ], [ %20, %14 ]
%16 = mul nuw nsw i64 %15, 70
%17 = getelementptr inbounds i8, i8* %1, i64 %16
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %17)
%19 = call i32 @imadd_fits(%struct.icom* %0, i8* %5)
%20 = add nuw nsw i64 %15, 1
%21 = icmp eq i64 %20, %13
br i1 %21, label %22, label %14
22: ; preds = %14, %2
ret void
}