#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 */
scalar_t__ do_test_read_append();
scalar_t__ do_test_read_seek_negative();
scalar_t__ do_test_write_append(char *);
scalar_t__ do_test_write_append_2(char *);
scalar_t__ do_test_write_append_without_null(char *);
int do_test(void) {
  int ret = 0;
  ret += do_test_write_append("a");
  ret += do_test_write_append_without_null("a");
  ret += do_test_write_append("a+");
  ret += do_test_write_append_without_null("a+");
  ret += do_test_read_append();
  ret += do_test_read_seek_negative();
  ret += do_test_write_append_2("test");
  ret += do_test_write_append_2("testing");
  return ret;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1060 <do_test_write_append@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
lea    0xe81(%rip),%rdi
call   1040 <do_test_write_append_without_null@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
call   1060 <do_test_write_append@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
lea    0xe51(%rip),%rdi
call   1040 <do_test_write_append_without_null@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1070 <do_test_read_append@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <do_test_read_seek_negative@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
lea    0xe13(%rip),%rdi
call   1050 <do_test_write_append_2@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
lea    0xdff(%rip),%rdi
call   1050 <do_test_write_append_2@plt>
mov    %rax,%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%r14
mov    %r14,%rdi
call   1060 <do_test_write_append@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <do_test_write_append_without_null@plt>
mov    %rax,%r12
add    %r15d,%r12d
lea    0xe83(%rip),%r14
mov    %r14,%rdi
call   1060 <do_test_write_append@plt>
mov    %rax,%rbx
add    %r12d,%ebx
mov    %r14,%rdi
call   1040 <do_test_write_append_without_null@plt>
mov    %rax,%r14
add    %ebx,%r14d
xor    %eax,%eax
call   1070 <do_test_read_append@plt>
mov    %rax,%rbx
add    %r14d,%ebx
xor    %eax,%eax
call   1030 <do_test_read_seek_negative@plt>
mov    %rax,%r14
add    %ebx,%r14d
lea    0xe49(%rip),%rdi
call   1050 <do_test_write_append_2@plt>
mov    %rax,%rbx
add    %r14d,%ebx
lea    0xe3c(%rip),%rdi
call   1050 <do_test_write_append_2@plt>
add    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"a\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [5 x i8] c"test\00"
@.str.3 = [8 x i8] c"testing\00"
define i32 @do_test() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 @do_test_write_append(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* %1
%4 = sext i32 %3 to i64
%5 = add nsw i64 %4, %2
%6 = trunc i64 %5 to i32
store i32 %6, i32* %1
%7 = call i64 @do_test_write_append_without_null(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = add nsw i64 %9, %7
%11 = trunc i64 %10 to i32
store i32 %11, i32* %1
%12 = call i64 @do_test_write_append(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = add nsw i64 %14, %12
%16 = trunc i64 %15 to i32
store i32 %16, i32* %1
%17 = call i64 @do_test_write_append_without_null(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %1
%22 = call i64 (...) @do_test_read_append()
%23 = load i32, i32* %1
%24 = sext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %1
%27 = call i64 (...) @do_test_read_seek_negative()
%28 = load i32, i32* %1
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %1
%32 = call i64 @do_test_write_append_2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %1
%34 = sext i32 %33 to i64
%35 = add nsw i64 %34, %32
%36 = trunc i64 %35 to i32
store i32 %36, i32* %1
%37 = call i64 @do_test_write_append_2(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %1
%39 = sext i32 %38 to i64
%40 = add nsw i64 %39, %37
%41 = trunc i64 %40 to i32
store i32 %41, i32* %1
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [2 x i8] c"a\00"
@.str.1 = [3 x i8] c"a+\00"
@.str.2 = [5 x i8] c"test\00"
@.str.3 = [8 x i8] c"testing\00"
define i32 @do_test() {
%1 = tail call i64 @do_test_write_append(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 @do_test_write_append_without_null(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = add i64 %2, %1
%4 = tail call i64 @do_test_write_append(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = add i64 %3, %4
%6 = tail call i64 @do_test_write_append_without_null(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = add i64 %5, %6
%8 = tail call i64 (...) @do_test_read_append()
%9 = add i64 %7, %8
%10 = tail call i64 (...) @do_test_read_seek_negative()
%11 = add i64 %9, %10
%12 = tail call i64 @do_test_write_append_2(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = add i64 %11, %12
%14 = tail call i64 @do_test_write_append_2(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%15 = add i64 %13, %14
%16 = trunc i64 %15 to i32
ret i32 %16
}