#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 */
int strlen(void *);
int /*<<< orphan*/ usage(char *);
void update_tree_entry(void **bufp, unsigned long *sizep) {
  void *buf = *bufp;
  unsigned long size = *sizep;
  int len = strlen(buf) + 1 + 20;
  if (size < len)
    usage("corrupt tree file");
  *bufp = buf + len;
  *sizep = size - len;
}


x86 assembly (clang, -O0):
<update_tree_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
add    $0x14,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmp    %rcx,%rax
jae    1175 <update_tree_entry+0x55>
lea    0xe90(%rip),%rdi
call   1040 <usage@plt>
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rax
sub    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_tree_entry>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    (%rdi),%rbx
mov    (%rsi),%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x15,%eax
movslq %eax,%r13
sub    %r13,%r12
jae    1154 <update_tree_entry+0x34>
lea    0xeb1(%rip),%rdi
call   1040 <usage@plt>
add    %r13,%rbx
mov    %rbx,(%r15)
mov    %r12,(%r14)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"corrupt tree file\00"
define void @update_tree_entry(i8** %0, i64* %1) {
%3 = alloca i8**
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8** %0, i8*** %3
store i64* %1, i64** %4
%8 = load i8**, i8*** %3
%9 = load i8*, i8** %8
store i8* %9, i8** %5
%10 = load i64*, i64** %4
%11 = load i64, i64* %10
store i64 %11, i64* %6
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, 1
%15 = add nsw i32 %14, 20
store i32 %15, i32* %7
%16 = load i64, i64* %6
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = icmp ult i64 %16, %18
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i8*, i8** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr i8, i8* %23, i64 %25
%27 = load i8**, i8*** %3
store i8* %26, i8** %27
%28 = load i64, i64* %6
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = sub i64 %28, %30
%32 = load i64*, i64** %4
store i64 %31, i64* %32
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"corrupt tree file\00"
define void @update_tree_entry(i8** nocapture %0, i64* nocapture %1) {
%3 = load i8*, i8** %0
%4 = load i64, i64* %1
%5 = tail call i32 @strlen(i8* %3)
%6 = add nsw i32 %5, 21
%7 = sext i32 %6 to i64
%8 = icmp ult i64 %4, %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @usage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = getelementptr i8, i8* %3, i64 %7
store i8* %12, i8** %0
%13 = sub i64 %4, %7
store i64 %13, i64* %1
ret void
}