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

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ upb_byteregion_copyall(struct _upb_byteregion const *,
                                          char *);
size_t upb_byteregion_len(struct _upb_byteregion const *);
char *upb_byteregion_strdup(const struct _upb_byteregion *r) {
  char *ret = malloc(upb_byteregion_len(r) + 1);
  upb_byteregion_copyall(r, ret);
  ret[upb_byteregion_len(r)] = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<upb_byteregion_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <upb_byteregion_len@plt>
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <upb_byteregion_copyall@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <upb_byteregion_len@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upb_byteregion_strdup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <upb_byteregion_len@plt>
lea    0x1(%rax),%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <upb_byteregion_copyall@plt>
mov    %r14,%rdi
call   1050 <upb_byteregion_len@plt>
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct._upb_byteregion = type { i32 }
define i8* @upb_byteregion_strdup(%struct._upb_byteregion* %0) {
%2 = alloca %struct._upb_byteregion*
%3 = alloca i8*
store %struct._upb_byteregion* %0, %struct._upb_byteregion** %2
%4 = load %struct._upb_byteregion*, %struct._upb_byteregion** %2
%5 = call i64 @upb_byteregion_len(%struct._upb_byteregion* %4)
%6 = add i64 %5, 1
%7 = trunc i64 %6 to i32
%8 = call i8* @malloc(i32 %7)
store i8* %8, i8** %3
%9 = load %struct._upb_byteregion*, %struct._upb_byteregion** %2
%10 = load i8*, i8** %3
%11 = call i32 @upb_byteregion_copyall(%struct._upb_byteregion* %9, i8* %10)
%12 = load i8*, i8** %3
%13 = load %struct._upb_byteregion*, %struct._upb_byteregion** %2
%14 = call i64 @upb_byteregion_len(%struct._upb_byteregion* %13)
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 0, i8* %15
%16 = load i8*, i8** %3
ret i8* %16
}

LLVM IR (-O2):
%struct._upb_byteregion = type { i32 }
define i8* @upb_byteregion_strdup(%struct._upb_byteregion* %0) {
%2 = tail call i64 @upb_byteregion_len(%struct._upb_byteregion* %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @upb_byteregion_copyall(%struct._upb_byteregion* %0, i8* %5)
%7 = tail call i64 @upb_byteregion_len(%struct._upb_byteregion* %0)
%8 = getelementptr inbounds i8, i8* %5, i64 %7
store i8 0, i8* %8
ret i8* %5
}