#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*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
int copy_name_server(char *in, char *out, int sz) {
  int found = 0;
  if ((strstr(in, "nameserver ")) == in) {
    if (strlen(in) < sz - 1)
      strncpy(out, in, sz - 1);
    else
      strcpy(out, in);
    out[sz - 1] = '\0';
    found = 1;
  }
  return found;
}


x86 assembly (clang, -O0):
<copy_name_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1060 <strstr@plt>
cmp    -0x8(%rbp),%rax
jne    11c8 <copy_name_server+0x88>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11a3 <copy_name_server+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
jmp    11b0 <copy_name_server+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_name_server>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea9(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    11a6 <copy_name_server+0x66>
mov    %rbx,%rdi
call   1060 <strlen@plt>
movslq %r15d,%rbp
add    $0xffffffffffffffff,%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
cmp    %ebp,%eax
jge    1197 <copy_name_server+0x57>
mov    %ebp,%edx
call   1030 <strncpy@plt>
jmp    119c <copy_name_server+0x5c>
call   1050 <strcpy@plt>
movb   $0x0,(%r14,%rbp,1)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"nameserver \00"
define i32 @copy_name_server(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 bitcast (i32 (i8*)* @strlen to i64 (i8*)*)(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %18
7: ; preds = %3
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %2, -1
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %9)
br label %15
13: ; preds = %7
%14 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %15
15: ; preds = %13, %11
%16 = sext i32 %9 to i64
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %15, %3
%19 = phi i32 [ 1, %15 ], [ 0, %3 ]
ret i32 %19
}