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

/* Variables and functions */
int /*<<< orphan*/ char_strcpy(char *, struct file_state *, char const *,
                               char const *);
size_t char_strlen(struct file_state *, char const *, char const *);
char *xcmalloc(size_t, char const *);
char *char_strdup(struct file_state *file, const char *start, const char *end,
                  const char *id) {
  char *str;
  size_t str_len;
  str_len = char_strlen(file, start, end);
  str = xcmalloc(str_len + 1, id);
  char_strcpy(str, file, start, end);
  str[str_len] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<char_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <char_strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rsi
call   1030 <xcmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <char_strcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_strdup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
call   1050 <char_strlen@plt>
mov    %rax,%rbp
lea    0x1(%rax),%rdi
mov    %r14,%rsi
call   1030 <xcmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <char_strcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.file_state = type { i32 }
define i8* @char_strdup(%struct.file_state* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.file_state*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store %struct.file_state* %0, %struct.file_state** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load %struct.file_state*, %struct.file_state** %5
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i64 @char_strlen(%struct.file_state* %11, i8* %12, i8* %13)
store i64 %14, i64* %10
%15 = load i64, i64* %10
%16 = add i64 %15, 1
%17 = load i8*, i8** %8
%18 = call i8* @xcmalloc(i64 %16, i8* %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = load %struct.file_state*, %struct.file_state** %5
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i32 @char_strcpy(i8* %19, %struct.file_state* %20, i8* %21, i8* %22)
%24 = load i8*, i8** %9
%25 = load i64, i64* %10
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %9
ret i8* %27
}

LLVM IR (-O2):
%struct.file_state = type { i32 }
define i8* @char_strdup(%struct.file_state* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i64 @char_strlen(%struct.file_state* %0, i8* %1, i8* %2)
%6 = add i64 %5, 1
%7 = tail call i8* @xcmalloc(i64 %6, i8* %3)
%8 = tail call i32 @char_strcpy(i8* %7, %struct.file_state* %0, i8* %1, i8* %2)
%9 = getelementptr inbounds i8, i8* %7, i64 %5
store i8 0, i8* %9
ret i8* %7
}