#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*/ assert(char *);
char *emalloc(int);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strippipe(char *string) {
  int i;
  char *retval;
  assert(string);
  for (i = 0; string[i] && (string[i] != '|'); i++)
    ;
  retval = emalloc(i + 1);
  strncpy(retval, string, i);
  retval[i] = '\0';
  return retval;
}


x86 assembly (clang, -O0):
<strippipe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     117b <strippipe+0x4b>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7c,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    118b <strippipe+0x5b>
jmp    119e <strippipe+0x6e>
jmp    1190 <strippipe+0x60>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    114c <strippipe+0x1c>
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1050 <emalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strippipe>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <assert@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%eax
test   %al,%al
je     1163 <strippipe+0x33>
cmp    $0x7c,%al
je     1163 <strippipe+0x33>
add    $0x1,%rbx
jmp    1150 <strippipe+0x20>
mov    %ebx,%r12d
lea    0x1(%rbx),%edi
call   1050 <emalloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r12,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strippipe(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @assert(i8* %5)
store i32 0, i32* %3
br label %7
7: ; preds = %26, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %7
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 124
br label %23
23: ; preds = %15, %7
%24 = phi i1 [ false, %7 ], [ %22, %15 ]
br i1 %24, label %25, label %29
25: ; preds = %23
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %7
29: ; preds = %23
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
%32 = call i8* @emalloc(i32 %31)
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = load i8*, i8** %2
%35 = load i32, i32* %3
%36 = call i32 @strncpy(i8* %33, i8* %34, i32 %35)
%37 = load i8*, i8** %4
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
%41 = load i8*, i8** %4
ret i8* %41
}

LLVM IR (-O2):
define i8* @strippipe(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
br label %3
3: ; preds = %7, %1
%4 = phi i64 [ %8, %7 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
switch i8 %6, label %7 [
i8 0, label %9
i8 124, label %9
]
7: ; preds = %3
%8 = add nuw i64 %4, 1
br label %3
9: ; preds = %3, %3
%10 = trunc i64 %4 to i32
%11 = and i64 %4, 4294967295
%12 = add nuw nsw i32 %10, 1
%13 = tail call i8* @emalloc(i32 %12)
%14 = tail call i32 @strncpy(i8* %13, i8* %0, i32 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %11
store i8 0, i8* %15
ret i8* %13
}