#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
int strlen(char *);
char *strndup(char *, int);
int main() {
  char *comando = malloc(256);
  printf("$ ");
  fgets(comando, 256, stdin);
  if ((strlen(comando) > 0) && (comando[strlen(comando) - 1] == '\n'))
    comando[strlen(comando) - 1] = '\0';
  char *segundaParte = strchr(comando, '|');
  if (segundaParte != NULL) {
    char *segundoComando;
    segundoComando = strndup(segundaParte + 1, strlen(segundaParte) - 1);
    printf("Segundo comando = [%s]\n", segundoComando);
  } else {
    printf("Primer comando [%s]\n", comando);
  }
  free(comando);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    120f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    120f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     126a <main+0xfa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
sub    $0x1,%esi
call   1070 <strndup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    127c <main+0x10c>
mov    -0x10(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x100,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    $0x100,%esi
call   1080 <fgets@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11d3 <main+0x63>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%r14,1)
jne    11d3 <main+0x63>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120b <main+0x9b>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    -0x1(%rax),%esi
mov    %rbx,%rdi
call   1070 <strndup@plt>
lea    0xdfd(%rip),%rdi
mov    %rax,%rsi
jmp    1215 <main+0xa5>
lea    0xe09(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [24 x i8] c"Segundo comando = [%s]\0A\00"
@.str.2 = [21 x i8] c"Primer comando [%s]\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
%5 = call i8* @malloc(i32 256)
store i8* %5, i8** %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 256, i32 %8)
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %0
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %14, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %30
23: ; preds = %13
%24 = load i8*, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
store i8 0, i8* %29
br label %30
30: ; preds = %23, %13, %0
%31 = load i8*, i8** %2
%32 = call i8* @strchr(i8* %31, i8 signext 124)
store i8* %32, i8** %3
%33 = load i8*, i8** %3
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i8*, i8** %3
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = call i8* @strndup(i8* %37, i32 %40)
store i8* %41, i8** %4
%42 = load i8*, i8** %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %47
44: ; preds = %30
%45 = load i8*, i8** %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %35
%48 = load i8*, i8** %2
%49 = call i32 @free(i8* %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"$ \00"
@stdin = global i32 0
@.str.1 = [24 x i8] c"Segundo comando = [%s]\0A\00"
@.str.2 = [21 x i8] c"Primer comando [%s]\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %1, i32 256, i32 %3)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = tail call i32 @strlen(i8* %1)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 10
br i1 %13, label %14, label %19
14: ; preds = %7
%15 = tail call i32 @strlen(i8* %1)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %14, %7, %0
%20 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 124)
%21 = icmp eq i8* %20, null
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = tail call i32 @strlen(i8* %20)
%25 = add nsw i32 %24, -1
%26 = tail call i8* @strndup(i8* %23, i32 %25)
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %30
28: ; preds = %19
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %30
30: ; preds = %28, %22
%31 = tail call i32 @free(i8* %1)
ret i32 0
}