#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 /*<<< orphan*/ exit(int);
int strlen(char *);
char *__copy_str(char *dst, char *src) {
  if (strlen(src) > 256) {
    exit(-1);
  }
  char *p = dst;
  while (*src != '\0') {
    *p++ = *src++;
  }
  *p = '\0';
  return dst;
}


x86 assembly (clang, -O0):
<__copy_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x100,%eax
jle    114e <__copy_str+0x2e>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118d <__copy_str+0x6d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1156 <__copy_str+0x36>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__copy_str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
cmp    $0x100,%eax
jg     116f <__copy_str+0x4f>
mov    (%rbx),%al
mov    %r14,%rcx
test   %al,%al
je     1161 <__copy_str+0x41>
add    $0x1,%rbx
mov    %r14,%rcx
nopl   0x0(%rax)
mov    %al,(%rcx)
add    $0x1,%rcx
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <__copy_str+0x30>
movb   $0x0,(%rcx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define i8* @__copy_str(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = call i32 @strlen(i8* %6)
%8 = icmp sgt i32 %7, 256
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i8*, i8** %3
store i8* %12, i8** %5
br label %13
13: ; preds = %18, %11
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %5
store i8 %21, i8* %22
br label %13
24: ; preds = %13
%25 = load i8*, i8** %5
store i8 0, i8* %25
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @__copy_str(i8* returned writeonly %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 256
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %18, label %10
8: ; preds = %2
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %5, %10
%11 = phi i8 [ %16, %10 ], [ %6, %5 ]
%12 = phi i8* [ %15, %10 ], [ %0, %5 ]
%13 = phi i8* [ %14, %10 ], [ %1, %5 ]
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %11, i8* %12
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %5
%19 = phi i8* [ %0, %5 ], [ %15, %10 ]
store i8 0, i8* %19
ret i8* %0
}