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

/* Variables and functions */
struct string_buffer *create_string_buffer();
int /*<<< orphan*/ string_buffer_append_chars(struct string_buffer *, char *,
                                              int);
int /*<<< orphan*/ string_buffer_append_string_buffer(struct string_buffer *,
                                                      struct string_buffer *);
int /*<<< orphan*/ string_buffer_clear(struct string_buffer *);
int /*<<< orphan*/ string_buffer_dispose(struct string_buffer *);
char *string_buffer_get_chars(struct string_buffer *);
int string_buffer_get_length(struct string_buffer *);
void string_buffer_drop_front(struct string_buffer *buffer, int length) {
  int length_buffer = string_buffer_get_length(buffer);
  if (length >= length_buffer) {
    string_buffer_clear(buffer);
  } else {
    char *chars = string_buffer_get_chars(buffer);
    struct string_buffer *temp = create_string_buffer();
    string_buffer_append_chars(temp, chars + length, length_buffer - length);
    string_buffer_clear(buffer);
    string_buffer_append_string_buffer(buffer, temp);
    string_buffer_dispose(temp);
  }
}


x86 assembly (clang, -O0):
<string_buffer_drop_front>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <string_buffer_get_length@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     11a5 <string_buffer_drop_front+0x35>
mov    -0x8(%rbp),%rdi
call   1090 <string_buffer_clear@plt>
jmp    11f6 <string_buffer_drop_front+0x86>
mov    -0x8(%rbp),%rdi
call   1060 <string_buffer_get_chars@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <create_string_buffer@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x10(%rbp),%edx
sub    -0xc(%rbp),%edx
call   1050 <string_buffer_append_chars@plt>
mov    -0x8(%rbp),%rdi
call   1090 <string_buffer_clear@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <string_buffer_append_string_buffer@plt>
mov    -0x20(%rbp),%rdi
call   1030 <string_buffer_dispose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_buffer_drop_front>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <string_buffer_get_length@plt>
mov    %eax,%ebp
sub    %r14d,%ebp
jle    11d2 <string_buffer_drop_front+0x62>
mov    %rbx,%rdi
call   1060 <string_buffer_get_chars@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <create_string_buffer@plt>
mov    %rax,%r12
movslq %r14d,%rsi
add    %r15,%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1050 <string_buffer_append_chars@plt>
mov    %rbx,%rdi
call   1090 <string_buffer_clear@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <string_buffer_append_string_buffer@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <string_buffer_dispose@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <string_buffer_clear@plt>

LLVM IR (-O0):
%struct.string_buffer = type { i32 }
define void @string_buffer_drop_front(%struct.string_buffer* %0, i32 %1) {
%3 = alloca %struct.string_buffer*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.string_buffer*
store %struct.string_buffer* %0, %struct.string_buffer** %3
store i32 %1, i32* %4
%8 = load %struct.string_buffer*, %struct.string_buffer** %3
%9 = call i32 @string_buffer_get_length(%struct.string_buffer* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp sge i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load %struct.string_buffer*, %struct.string_buffer** %3
%15 = call i32 @string_buffer_clear(%struct.string_buffer* %14)
br label %36
16: ; preds = %2
%17 = load %struct.string_buffer*, %struct.string_buffer** %3
%18 = call i8* @string_buffer_get_chars(%struct.string_buffer* %17)
store i8* %18, i8** %6
%19 = call %struct.string_buffer* (...) @create_string_buffer()
store %struct.string_buffer* %19, %struct.string_buffer** %7
%20 = load %struct.string_buffer*, %struct.string_buffer** %7
%21 = load i8*, i8** %6
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = sub nsw i32 %25, %26
%28 = call i32 @string_buffer_append_chars(%struct.string_buffer* %20, i8* %24, i32 %27)
%29 = load %struct.string_buffer*, %struct.string_buffer** %3
%30 = call i32 @string_buffer_clear(%struct.string_buffer* %29)
%31 = load %struct.string_buffer*, %struct.string_buffer** %3
%32 = load %struct.string_buffer*, %struct.string_buffer** %7
%33 = call i32 @string_buffer_append_string_buffer(%struct.string_buffer* %31, %struct.string_buffer* %32)
%34 = load %struct.string_buffer*, %struct.string_buffer** %7
%35 = call i32 @string_buffer_dispose(%struct.string_buffer* %34)
br label %36
36: ; preds = %16, %13
ret void
}

LLVM IR (-O2):
%struct.string_buffer = type { i32 }
define void @string_buffer_drop_front(%struct.string_buffer* %0, i32 %1) {
%3 = tail call i32 @string_buffer_get_length(%struct.string_buffer* %0)
%4 = icmp sgt i32 %3, %1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @string_buffer_clear(%struct.string_buffer* %0)
br label %17
7: ; preds = %2
%8 = tail call i8* @string_buffer_get_chars(%struct.string_buffer* %0)
%9 = tail call %struct.string_buffer* (...) @create_string_buffer()
%10 = sext i32 %1 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = sub nsw i32 %3, %1
%13 = tail call i32 @string_buffer_append_chars(%struct.string_buffer* %9, i8* %11, i32 %12)
%14 = tail call i32 @string_buffer_clear(%struct.string_buffer* %0)
%15 = tail call i32 @string_buffer_append_string_buffer(%struct.string_buffer* %0, %struct.string_buffer* %9)
%16 = tail call i32 @string_buffer_dispose(%struct.string_buffer* %9)
br label %17
17: ; preds = %7, %5
ret void
}