#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ replace_plus(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *, int *,
                          int *, char *, char *);
int strlen(char *);
void show_posts() {
  FILE *f = fopen("guestbook.txt", "r");
  char *read;
  char *file_line = malloc(350);
  int day, month, year, hour, minute, second;
  char *name = malloc(50);
  char *message = malloc(250);
  printf("<ul>");
  while ((read = fgets(file_line, 350, f)) != NULL) {
    sscanf(file_line, "%d/%d/%d %d:%d:%d %s %s", &day, &month, &year, &hour,
           &minute, &second, name, message);
    replace_plus(name, name + strlen(name));
    replace_plus(message, message + strlen(message));
    printf("<li>Message posted by %s at %d/%d/%d %d:%d:%d : %s</li>", name, day,
           month, year, hour, minute, second, message);
  }
  printf("</ul>");
  fclose(f);
}


x86 assembly (clang, -O0):
<show_posts>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x88,%rsp
lea    0xe6d(%rip),%rdi
lea    0xe74(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0x15e,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    $0xfa,%edi
call   1070 <malloc@plt>
mov    %rax,-0x48(%rbp)
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x15e,%esi
call   1060 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12d3 <show_posts+0x153>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%r10
mov    -0x48(%rbp),%rax
lea    0xe07(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%r8
lea    -0x30(%rbp),%r9
lea    -0x34(%rbp),%rbx
lea    -0x38(%rbp),%r11
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1080 <sscanf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdi
cltq
add    %rax,%rsi
call   1090 <replace_plus@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rsi
mov    -0x50(%rbp),%rdi
cltq
add    %rax,%rsi
call   1090 <replace_plus@plt>
mov    -0x40(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
mov    -0x34(%rbp),%r11d
mov    -0x38(%rbp),%r10d
mov    -0x48(%rbp),%rax
lea    0xd74(%rip),%rdi
mov    %r11d,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11db <show_posts+0x5b>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_posts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe72(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    $0x15e,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
mov    $0x32,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    $0xfa,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x15e,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1297 <show_posts+0x117>
mov    %r15,%rdi
lea    0xe12(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
push   %r13
push   %r12
lea    0x10(%rsp),%rax
push   %rax
lea    0x1c(%rsp),%rax
push   %rax
call   1080 <sscanf@plt>
add    $0x20,%rsp
mov    %r12,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r12,%rsi
mov    %r12,%rdi
call   1090 <replace_plus@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %eax,%rsi
add    %r13,%rsi
mov    %r13,%rdi
call   1090 <replace_plus@plt>
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x8(%rsp),%r9d
mov    0x4(%rsp),%ebp
mov    (%rsp),%ebx
sub    $0x8,%rsp
lea    0xdad(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
push   %r13
push   %rbx
push   %rbp
call   1050 <printf@plt>
add    $0x20,%rsp
jmp    11e0 <show_posts+0x60>
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"guestbook.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"<ul>\00"
@.str.3 = [24 x i8] c"%d/%d/%d %d:%d:%d %s %s\00"
@.str.4 = [56 x i8] c"<li>Message posted by %s at %d/%d/%d %d:%d:%d : %s</li>\00"
@.str.5 = [6 x i8] c"</ul>\00"
define void @show_posts() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %1
%13 = call i8* @malloc(i32 350)
store i8* %13, i8** %3
%14 = call i8* @malloc(i32 50)
store i8* %14, i8** %10
%15 = call i8* @malloc(i32 250)
store i8* %15, i8** %11
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %22, %0
%18 = load i8*, i8** %3
%19 = load i32*, i32** %1
%20 = call i8* @fgets(i8* %18, i32 350, i32* %19)
store i8* %20, i8** %2
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %50
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = load i8*, i8** %10
%25 = load i8*, i8** %11
%26 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %4, i32* %5, i32* %6, i32* %7, i32* %8, i32* %9, i8* %24, i8* %25)
%27 = load i8*, i8** %10
%28 = load i8*, i8** %10
%29 = load i8*, i8** %10
%30 = call i32 @strlen(i8* %29)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = call i32 @replace_plus(i8* %27, i8* %32)
%34 = load i8*, i8** %11
%35 = load i8*, i8** %11
%36 = load i8*, i8** %11
%37 = call i32 @strlen(i8* %36)
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = call i32 @replace_plus(i8* %34, i8* %39)
%41 = load i8*, i8** %10
%42 = load i32, i32* %4
%43 = load i32, i32* %5
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = load i8*, i8** %11
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %41, i32 %42, i32 %43, i32 %44, i32 %45, i32 %46, i32 %47, i8* %48)
br label %17
50: ; preds = %17
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%52 = load i32*, i32** %1
%53 = call i32 @fclose(i32* %52)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"guestbook.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"<ul>\00"
@.str.3 = [24 x i8] c"%d/%d/%d %d:%d:%d %s %s\00"
@.str.4 = [56 x i8] c"<li>Message posted by %s at %d/%d/%d %d:%d:%d : %s</li>\00"
@.str.5 = [6 x i8] c"</ul>\00"
define void @show_posts() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call dereferenceable_or_null(350) i8* @malloc(i32 350)
%9 = bitcast i32* %1 to i8*
%10 = bitcast i32* %2 to i8*
%11 = bitcast i32* %3 to i8*
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
%14 = bitcast i32* %6 to i8*
%15 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%16 = tail call dereferenceable_or_null(250) i8* @malloc(i32 250)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = call i8* @fgets(i8* %8, i32 350, i32* %7)
%19 = icmp eq i8* %18, null
br i1 %19, label %39, label %20
20: ; preds = %0, %20
%21 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4, i32* %5, i32* %6, i8* %15, i8* %16)
%22 = call i32 @strlen(i8* %15)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
%25 = call i32 @replace_plus(i8* %15, i8* %24)
%26 = call i32 @strlen(i8* %16)
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %16, i64 %27
%29 = call i32 @replace_plus(i8* %16, i8* %28)
%30 = load i32, i32* %1
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 %30, i32 %31, i32 %32, i32 %33, i32 %34, i32 %35, i8* %16)
%37 = call i8* @fgets(i8* %8, i32 350, i32* %7)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %20
39: ; preds = %20, %0
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @fclose(i32* %7)
ret void
}