#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 buffer {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ buffer_copy(struct buffer *, struct buffer *, int);
struct buffer *buffer_new();
int /*<<< orphan*/ buffer_putc(struct buffer *, char);
int buffer_size(struct buffer *);
int /*<<< orphan*/ buffer_zero(struct buffer *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  struct buffer *a, *b;
  a = buffer_new();
  b = buffer_new();
  buffer_putc(a, 'a');
  buffer_putc(a, 'g');
  buffer_copy(b, a, buffer_size(a));
  buffer_copy(b, a, buffer_size(a));
  buffer_zero(b);
  printf("buf sz = %d\n", buffer_size(b));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <buffer_new@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <buffer_new@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x61,%esi
call   1040 <buffer_putc@plt>
mov    -0x10(%rbp),%rdi
mov    $0x67,%esi
call   1040 <buffer_putc@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <buffer_size@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1070 <buffer_copy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <buffer_size@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1070 <buffer_copy@plt>
mov    -0x18(%rbp),%rdi
call   1050 <buffer_zero@plt>
mov    -0x18(%rbp),%rdi
call   1080 <buffer_size@plt>
mov    %eax,%esi
lea    0xdf4(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <buffer_new@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <buffer_new@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x61,%esi
call   1040 <buffer_putc@plt>
mov    %rbx,%rdi
mov    $0x67,%esi
call   1040 <buffer_putc@plt>
mov    %rbx,%rdi
call   1080 <buffer_size@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <buffer_copy@plt>
mov    %rbx,%rdi
call   1080 <buffer_size@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <buffer_copy@plt>
mov    %r14,%rdi
call   1050 <buffer_zero@plt>
mov    %r14,%rdi
call   1080 <buffer_size@plt>
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
@.str = [13 x i8] c"buf sz = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.buffer*
%3 = alloca %struct.buffer*
store i32 0, i32* %1
%4 = call %struct.buffer* (...) @buffer_new()
store %struct.buffer* %4, %struct.buffer** %2
%5 = call %struct.buffer* (...) @buffer_new()
store %struct.buffer* %5, %struct.buffer** %3
%6 = load %struct.buffer*, %struct.buffer** %2
%7 = call i32 @buffer_putc(%struct.buffer* %6, i8 signext 97)
%8 = load %struct.buffer*, %struct.buffer** %2
%9 = call i32 @buffer_putc(%struct.buffer* %8, i8 signext 103)
%10 = load %struct.buffer*, %struct.buffer** %3
%11 = load %struct.buffer*, %struct.buffer** %2
%12 = load %struct.buffer*, %struct.buffer** %2
%13 = call i32 @buffer_size(%struct.buffer* %12)
%14 = call i32 @buffer_copy(%struct.buffer* %10, %struct.buffer* %11, i32 %13)
%15 = load %struct.buffer*, %struct.buffer** %3
%16 = load %struct.buffer*, %struct.buffer** %2
%17 = load %struct.buffer*, %struct.buffer** %2
%18 = call i32 @buffer_size(%struct.buffer* %17)
%19 = call i32 @buffer_copy(%struct.buffer* %15, %struct.buffer* %16, i32 %18)
%20 = load %struct.buffer*, %struct.buffer** %3
%21 = call i32 @buffer_zero(%struct.buffer* %20)
%22 = load %struct.buffer*, %struct.buffer** %3
%23 = call i32 @buffer_size(%struct.buffer* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %23)
ret i32 0
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@.str = [13 x i8] c"buf sz = %d\0A\00"
define i32 @main() {
%1 = tail call %struct.buffer* (...) @buffer_new()
%2 = tail call %struct.buffer* (...) @buffer_new()
%3 = tail call i32 @buffer_putc(%struct.buffer* %1, i8 signext 97)
%4 = tail call i32 @buffer_putc(%struct.buffer* %1, i8 signext 103)
%5 = tail call i32 @buffer_size(%struct.buffer* %1)
%6 = tail call i32 @buffer_copy(%struct.buffer* %2, %struct.buffer* %1, i32 %5)
%7 = tail call i32 @buffer_size(%struct.buffer* %1)
%8 = tail call i32 @buffer_copy(%struct.buffer* %2, %struct.buffer* %1, i32 %7)
%9 = tail call i32 @buffer_zero(%struct.buffer* %2)
%10 = tail call i32 @buffer_size(%struct.buffer* %2)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}