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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int buf_cap(struct buf *);
int /*<<< orphan*/ buf_free(struct buf *);
struct buf *buf_new(char *);
int /*<<< orphan*/ buf_puts(struct buf *, char *);
void case_buf_cap() {
  struct buf *buf = buf_new("abcdef");
  assert(buf_cap(buf) == 6);
  buf_puts(buf, "abc");
  assert(buf_cap(buf) == 12);
  buf_free(buf);
}


x86 assembly (clang, -O0):
<case_buf_cap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <buf_new@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <buf_cap@plt>
cmp    $0x6,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <buf_puts@plt>
mov    -0x8(%rbp),%rdi
call   1070 <buf_cap@plt>
cmp    $0xc,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1060 <buf_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<case_buf_cap>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1030 <buf_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <buf_cap@plt>
xor    %edi,%edi
cmp    $0x6,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <buf_puts@plt>
mov    %rbx,%rdi
call   1070 <buf_cap@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <buf_free@plt>

LLVM IR (-O0):
%struct.buf = type { i32 }
@.str = [7 x i8] c"abcdef\00"
@.str.1 = [4 x i8] c"abc\00"
define void @case_buf_cap() {
%1 = alloca %struct.buf*
%2 = call %struct.buf* @buf_new(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store %struct.buf* %2, %struct.buf** %1
%3 = load %struct.buf*, %struct.buf** %1
%4 = call i32 @buf_cap(%struct.buf* %3)
%5 = icmp eq i32 %4, 6
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load %struct.buf*, %struct.buf** %1
%9 = call i32 @buf_puts(%struct.buf* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%10 = load %struct.buf*, %struct.buf** %1
%11 = call i32 @buf_cap(%struct.buf* %10)
%12 = icmp eq i32 %11, 12
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load %struct.buf*, %struct.buf** %1
%16 = call i32 @buf_free(%struct.buf* %15)
ret void
}

LLVM IR (-O2):
%struct.buf = type { i32 }
@.str = [7 x i8] c"abcdef\00"
@.str.1 = [4 x i8] c"abc\00"
define void @case_buf_cap() {
%1 = tail call %struct.buf* @buf_new(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @buf_cap(%struct.buf* %1)
%3 = icmp eq i32 %2, 6
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @buf_puts(%struct.buf* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @buf_cap(%struct.buf* %1)
%8 = icmp eq i32 %7, 12
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @buf_free(%struct.buf* %1)
ret void
}