#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 str_len(char *);
int /*<<< orphan*/ write_to_vga(int /*<<< orphan*/, char);
void print_hf(int line, char *str, char attr) {
  int i;
  int j = line * 160;
  int spaces = (80 - str_len(str)) / 2;
  for (i = 0; i < spaces; i++) {
    write_to_vga(j++, ' ');
    write_to_vga(j++, attr);
  }
  for (i = 0; i < str_len(str); i++) {
    write_to_vga(j++, str[i]);
    write_to_vga(j++, attr);
  }
  for (i = 0; i < 80 - spaces - str_len(str); i++) {
    write_to_vga(j++, ' ');
    write_to_vga(j++, attr);
  }
}


x86 assembly (clang, -O0):
<print_hf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
imul   $0xa0,-0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <str_len@plt>
mov    %eax,%ecx
mov    $0x50,%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11a5 <print_hf+0x85>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x20,%esi
call   1030 <write_to_vga@plt>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%esi
call   1030 <write_to_vga@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <print_hf+0x42>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <str_len@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    1206 <print_hf+0xe6>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <write_to_vga@plt>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%esi
call   1030 <write_to_vga@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ac <print_hf+0x8c>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x50,%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <str_len@plt>
mov    -0x2c(%rbp),%ecx
mov    %eax,%edx
mov    -0x28(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jge    1270 <print_hf+0x150>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x20,%esi
call   1030 <write_to_vga@plt>
mov    -0x1c(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%esi
call   1030 <write_to_vga@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120d <print_hf+0xed>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
shl    $0x5,%edi
lea    (%rdi,%rdi,4),%ebx
mov    %rsi,%rdi
call   1040 <str_len@plt>
mov    $0x50,%ecx
sub    %eax,%ecx
mov    %ecx,%r12d
shr    $0x1f,%r12d
add    %ecx,%r12d
sar    %r12d
movsbl %bpl,%r15d
cmp    $0x4e,%eax
jg     1193 <print_hf+0x73>
cmp    $0x2,%r12d
mov    $0x1,%ebp
cmovge %r12d,%ebp
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r13d
mov    %ebx,%edi
mov    $0x20,%esi
call   1030 <write_to_vga@plt>
add    $0x2,%ebx
mov    %r13d,%edi
mov    %r15d,%esi
call   1030 <write_to_vga@plt>
add    $0xffffffff,%ebp
jne    1170 <print_hf+0x50>
mov    %r14,%rdi
call   1040 <str_len@plt>
test   %eax,%eax
jle    11e4 <print_hf+0xc4>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%r13d
or     $0x1,%r13d
movsbl (%r14,%rbp,1),%esi
mov    %ebx,%edi
call   1030 <write_to_vga@plt>
add    $0x2,%ebx
mov    %r13d,%edi
mov    %r15d,%esi
call   1030 <write_to_vga@plt>
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <str_len@plt>
cltq
cmp    %rax,%rbp
jl     11b0 <print_hf+0x90>
mov    %r14,%rdi
call   1040 <str_len@plt>
mov    $0x50,%r13d
sub    %r12d,%r13d
mov    %r13d,%ecx
sub    %eax,%ecx
test   %ecx,%ecx
jle    1235 <print_hf+0x115>
xor    %ebp,%ebp
mov    %ebx,%r12d
or     $0x1,%r12d
mov    %ebx,%edi
mov    $0x20,%esi
call   1030 <write_to_vga@plt>
add    $0x2,%ebx
mov    %r12d,%edi
mov    %r15d,%esi
call   1030 <write_to_vga@plt>
add    $0x1,%ebp
mov    %r14,%rdi
call   1040 <str_len@plt>
mov    %r13d,%ecx
sub    %eax,%ecx
cmp    %ecx,%ebp
jl     1200 <print_hf+0xe0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @print_hf(i32 %0, i8* %1, i8 signext %2) {
%4 = mul nsw i32 %0, 160
%5 = tail call i32 @str_len(i8* %1)
%6 = sub nsw i32 80, %5
%7 = sdiv i32 %6, 2
%8 = icmp slt i32 %5, 79
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @llvm.smax.i32(i32 %7, i32 1)
br label %15
11: ; preds = %15, %3
%12 = phi i32 [ %4, %3 ], [ %20, %15 ]
%13 = tail call i32 @str_len(i8* %1)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %30, label %24
15: ; preds = %9, %15
%16 = phi i32 [ %22, %15 ], [ 0, %9 ]
%17 = phi i32 [ %20, %15 ], [ %4, %9 ]
%18 = or i32 %17, 1
%19 = tail call i32 @write_to_vga(i32 %17, i8 signext 32)
%20 = add nsw i32 %17, 2
%21 = tail call i32 @write_to_vga(i32 %18, i8 signext %2)
%22 = add nuw nsw i32 %16, 1
%23 = icmp eq i32 %22, %10
br i1 %23, label %11, label %15
24: ; preds = %30, %11
%25 = phi i32 [ %12, %11 ], [ %37, %30 ]
%26 = tail call i32 @str_len(i8* %1)
%27 = sub nsw i32 80, %7
%28 = sub i32 %27, %26
%29 = icmp sgt i32 %28, 0
br i1 %29, label %43, label %54
30: ; preds = %11, %30
%31 = phi i64 [ %39, %30 ], [ 0, %11 ]
%32 = phi i32 [ %37, %30 ], [ %12, %11 ]
%33 = or i32 %32, 1
%34 = getelementptr inbounds i8, i8* %1, i64 %31
%35 = load i8, i8* %34
%36 = tail call i32 @write_to_vga(i32 %32, i8 signext %35)
%37 = add nsw i32 %32, 2
%38 = tail call i32 @write_to_vga(i32 %33, i8 signext %2)
%39 = add nuw nsw i64 %31, 1
%40 = tail call i32 @str_len(i8* %1)
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %30, label %24
43: ; preds = %24, %43
%44 = phi i32 [ %50, %43 ], [ 0, %24 ]
%45 = phi i32 [ %48, %43 ], [ %25, %24 ]
%46 = or i32 %45, 1
%47 = tail call i32 @write_to_vga(i32 %45, i8 signext 32)
%48 = add nsw i32 %45, 2
%49 = tail call i32 @write_to_vga(i32 %46, i8 signext %2)
%50 = add nuw nsw i32 %44, 1
%51 = tail call i32 @str_len(i8* %1)
%52 = sub i32 %27, %51
%53 = icmp slt i32 %50, %52
br i1 %53, label %43, label %54
54: ; preds = %43, %24
ret void
}