#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 /*<<< orphan*/ buf_free(struct buf *);
int /*<<< orphan*/ buf_lrm(struct buf *, int);
struct buf *buf_new(char *);
int /*<<< orphan*/ buf_str(struct buf *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
void case_buf_lrm() {
  struct buf *buf = buf_new("testabcdef");
  buf_lrm(buf, 4);
  assert(strcmp(buf_str(buf), "abcdef") == 0);
  buf_lrm(buf, 100);
  assert(strcmp(buf_str(buf), "") == 0);
  buf_free(buf);
}


x86 assembly (clang, -O0):
<case_buf_lrm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1030 <buf_new@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x4,%esi
call   1060 <buf_lrm@plt>
mov    -0x8(%rbp),%rdi
call   1080 <buf_str@plt>
mov    %eax,%edi
lea    0xe6c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    $0x64,%esi
call   1060 <buf_lrm@plt>
mov    -0x8(%rbp),%rdi
call   1080 <buf_str@plt>
mov    %eax,%edi
lea    0xe3c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1070 <buf_free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<case_buf_lrm>:
push   %rbx
lea    0xe98(%rip),%rdi
call   1030 <buf_new@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4,%esi
call   1060 <buf_lrm@plt>
mov    %rbx,%rdi
call   1080 <buf_str@plt>
lea    0xe78(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <buf_lrm@plt>
mov    %rbx,%rdi
call   1080 <buf_str@plt>
lea    0xe4d(%rip),%rsi
mov    %eax,%edi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <buf_free@plt>

LLVM IR (-O0):
%struct.buf = type { i32 }
@.str = [11 x i8] c"testabcdef\00"
@.str.1 = [7 x i8] c"abcdef\00"
@.str.2 = [1 x i8] zeroinitializer
define void @case_buf_lrm() {
%1 = alloca %struct.buf*
%2 = call %struct.buf* @buf_new(i8* getelementptr inbounds ([11 x i8], [11 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_lrm(%struct.buf* %3, i32 4)
%5 = load %struct.buf*, %struct.buf** %1
%6 = call i32 @buf_str(%struct.buf* %5)
%7 = call i64 @strcmp(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load %struct.buf*, %struct.buf** %1
%12 = call i32 @buf_lrm(%struct.buf* %11, i32 100)
%13 = load %struct.buf*, %struct.buf** %1
%14 = call i32 @buf_str(%struct.buf* %13)
%15 = call i64 @strcmp(i32 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load %struct.buf*, %struct.buf** %1
%20 = call i32 @buf_free(%struct.buf* %19)
ret void
}

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