#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 */
char *emalloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *pipe_scan(char *line) {
  int i;
  char *retval;
  for (i = 0; line[i] && line[i] != '|'; i++)
    ;
  if (!i || i == strlen(line))
    return NULL;
  retval = emalloc(strlen(line) - i + 1);
  strcpy(retval, line + i + 1);
  return retval;
}


x86 assembly (clang, -O0):
<pipe_scan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1172 <pipe_scan+0x42>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7c,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1182 <pipe_scan+0x52>
jmp    1195 <pipe_scan+0x65>
jmp    1187 <pipe_scan+0x57>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <pipe_scan+0x13>
cmpl   $0x0,-0x14(%rbp)
je     11bb <pipe_scan+0x8b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jne    11c8 <pipe_scan+0x98>
movq   $0x0,-0x8(%rbp)
jmp    1202 <pipe_scan+0xd2>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
sub    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <emalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_scan>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%eax
test   %al,%al
je     1153 <pipe_scan+0x23>
cmp    $0x7c,%al
je     1153 <pipe_scan+0x23>
add    $0x1,%rbx
jmp    1140 <pipe_scan+0x10>
test   %ebx,%ebx
je     1163 <pipe_scan+0x33>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    %ebx,%eax
jne    1167 <pipe_scan+0x37>
xor    %ebx,%ebx
jmp    1191 <pipe_scan+0x61>
mov    %ebx,%r14d
add    %r15,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
sub    %ebx,%eax
lea    0x1(%rax),%edi
call   1050 <emalloc@plt>
mov    %rax,%rbx
add    $0x1,%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @pipe_scan(i8* %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i64 [ %7, %6 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 0, label %8
i8 124, label %8
]
6: ; preds = %2
%7 = add nuw i64 %3, 1
br label %2
8: ; preds = %2, %2
%9 = trunc i64 %3 to i32
%10 = and i64 %3, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = icmp eq i32 %9, 0
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = tail call i32 @strlen(i8* %0)
%15 = icmp eq i32 %14, %9
br i1 %15, label %23, label %16
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %0)
%18 = sub nsw i32 1, %9
%19 = add i32 %18, %17
%20 = tail call i8* @emalloc(i32 %19)
%21 = getelementptr inbounds i8, i8* %11, i64 1
%22 = tail call i32 @strcpy(i8* %20, i8* %21)
br label %23
23: ; preds = %8, %13, %16
%24 = phi i8* [ %20, %16 ], [ null, %13 ], [ null, %8 ]
ret i8* %24
}