#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 CharOf(char);
scalar_t__ strchr(char const *, int);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
int replace_nulls(char *target, const char *source) {
  int len = (int)strlen(source);
  int j;
  (void)strcpy(target, source);
  if (strchr(source, 0200) != 0) {
    for (j = 0; j < len; j++)
      if (CharOf(target[j]) == 0200)
        target[j] = '\0';
  }
  return len;
}


x86 assembly (clang, -O0):
<replace_nulls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    $0x80,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11d4 <replace_nulls+0x94>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11cf <replace_nulls+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <CharOf@plt>
cmp    $0x80,%eax
jne    11bc <replace_nulls+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c1 <replace_nulls+0x81>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1188 <replace_nulls+0x48>
jmp    11d4 <replace_nulls+0x94>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_nulls>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r14
mov    %r12,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
mov    $0x80,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11b1 <replace_nulls+0x71>
test   %r14d,%r14d
jle    11b1 <replace_nulls+0x71>
mov    %r14d,%r15d
xor    %ebx,%ebx
jmp    1199 <replace_nulls+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b1 <replace_nulls+0x71>
movsbl (%r12,%rbx,1),%edi
call   1060 <CharOf@plt>
cmp    $0x80,%eax
jne    1190 <replace_nulls+0x50>
movb   $0x0,(%r12,%rbx,1)
jmp    1190 <replace_nulls+0x50>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @replace_nulls(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %5
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %4
%14 = call i64 @strchr(i8* %13, i32 128)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %2
store i32 0, i32* %6
br label %17
17: ; preds = %35, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @CharOf(i8 signext %26)
%28 = icmp eq i32 %27, 128
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %29, %21
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %17
38: ; preds = %17
br label %39
39: ; preds = %38, %2
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
define i32 @replace_nulls(i8* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @strcpy(i8* %0, i8* %1)
%6 = tail call i64 @strchr(i8* %1, i32 128)
%7 = icmp ne i64 %6, 0
%8 = icmp sgt i32 %4, 0
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = and i64 %3, 4294967295
br label %12
12: ; preds = %10, %19
%13 = phi i64 [ 0, %10 ], [ %20, %19 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = tail call i32 @CharOf(i8 signext %15)
%17 = icmp eq i32 %16, 128
br i1 %17, label %18, label %19
18: ; preds = %12
store i8 0, i8* %14
br label %19
19: ; preds = %12, %18
%20 = add nuw nsw i64 %13, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %22, label %12
22: ; preds = %19, %2
ret i32 %4
}