#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int append_to_buf(char *buf, char *line) {
  if (strlen(buf) + strlen(line) >= 4096) {
    fprintf(stderr, "Para is too long (> %d bytes)\n", 4096);
    return 1;
  } else {
    strcat(buf, line);
    return 0;
  }
}


x86 assembly (clang, -O0):
<append_to_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
cmp    $0x1000,%eax
jl     118d <append_to_buf+0x5d>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe89(%rip),%rsi
mov    $0x1000,%edx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a1 <append_to_buf+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_to_buf>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
cmp    $0x1000,%eax
jl     1173 <append_to_buf+0x43>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
mov    $0x1000,%edx
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1180 <append_to_buf+0x50>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Para is too long (> %d bytes)\0A\00"
define i32 @append_to_buf(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = load i8*, i8** %5
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %7, %9
%11 = icmp sge i32 %10, 4096
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 4096)
store i32 1, i32* %3
br label %19
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %16, i8* %17)
store i32 0, i32* %3
br label %19
19: ; preds = %15, %12
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Para is too long (> %d bytes)\0A\00"
define i32 @append_to_buf(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, %3
%6 = icmp sgt i32 %5, 4095
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 4096)
br label %12
10: ; preds = %2
%11 = tail call i32 @strcat(i8* %0, i8* %1)
br label %12
12: ; preds = %10, %7
%13 = phi i32 [ 1, %7 ], [ 0, %10 ]
ret i32 %13
}