char *copy_string(str)
register char *str;
{
  register char *c;
  char *copy;
  for (c = str; *c; ++c)
    ;
  copy = (char *)yy_flex_alloc((c - str + 1) * sizeof(char));
  if (copy == ((void *)0))
    flexfatal("dynamic memory failure in copy_string()");
  for (c = copy; (*c++ = *str++);)
    ;
  return copy;
}


x86 assembly (clang, -O0):
<copy_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1157 <copy_string+0x37>
jmp    1146 <copy_string+0x26>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <copy_string+0x14>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
sub    %rax,%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
mov    $0x0,%al
call   1030 <yy_flex_alloc@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <copy_string+0x70>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <flexfatal@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %al,(%rcx)
cmp    $0x0,%al
je     11c7 <copy_string+0xa7>
jmp    1198 <copy_string+0x78>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_string>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%rbx,%rdi,1)
lea    0x1(%rdi),%rdi
jne    1130 <copy_string+0x10>
xor    %eax,%eax
call   1030 <yy_flex_alloc@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1155 <copy_string+0x35>
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1040 <flexfatal@plt>
movslq %ebp,%rax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%rcx,1),%edx
mov    %dl,(%rax,%rcx,1)
add    $0x1,%rcx
test   %dl,%dl
jne    1160 <copy_string+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"dynamic memory failure in copy_string()\00"
define i8* @copy_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %11, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
br label %11
11: ; preds = %10
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %3
br label %6
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = add nsw i64 %19, 1
%21 = mul i64 %20, 1
%22 = call i32 (i64, ...) bitcast (i32 (...)* @yy_flex_alloc to i32 (i64, ...)*)(i64 %21)
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %29
27: ; preds = %14
%28 = call i32 (i8*, ...) bitcast (i32 (...)* @flexfatal to i32 (i8*, ...)*)(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %14
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %31
31: ; preds = %38, %29
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
%34 = load i8, i8* %32
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %3
store i8 %34, i8* %35
%37 = icmp ne i8 %34, 0
br i1 %37, label %38, label %39
38: ; preds = %31
br label %31
39: ; preds = %31
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@.str = [40 x i8] c"dynamic memory failure in copy_string()\00"
define i8* @copy_string(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
%6 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = ptrtoint i8* %3 to i64
%9 = ptrtoint i8* %0 to i64
%10 = sub i64 1, %9
%11 = add i64 %10, %8
%12 = tail call i32 (i64, ...) bitcast (i32 (...)* @yy_flex_alloc to i32 (i64, ...)*)(i64 %11)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i32 %12, 0
br i1 %15, label %16, label %18
16: ; preds = %7
%17 = tail call i32 (i8*, ...) bitcast (i32 (...)* @flexfatal to i32 (i8*, ...)*)(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %7
br label %19
19: ; preds = %18, %19
%20 = phi i8* [ %24, %19 ], [ %14, %18 ]
%21 = phi i8* [ %22, %19 ], [ %0, %18 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8, i8* %21
%24 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %23, i8* %20
%25 = icmp eq i8 %23, 0
br i1 %25, label %26, label %19
26: ; preds = %19
ret i8* %14
}