#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  char *texto = "adss";
  int pidChild;
  int fd[2];
  pipe(fd);
  if ((pidChild = fork()) == -1) {
    perror("Bad Fork!");
    exit(1);
  }
  if (pidChild == 0) {
    dup2(fd[0], STDIN_FILENO);
    close(fd[1]);
    close(fd[0]);
    char *argv[] = {"python", "meu_script.py", NULL};
    if (execvp("python", argv) < 0) {
      perror("Bad Exec");
      exit(1);
    }
  } else {
    close(fd[0]);
    FILE *fp = fdopen(fd[1], "w");
    fprintf(fp, "%s\n", "Minha terra tem palmeiras");
    fprintf(fp, "%s\n", "Onde canta o sabiá");
    fprintf(fp, "%s\n", "<3 SOs");
    fclose(fp);
    close(fd[1]);
    int status;
    waitpid(pidChild, &status, 0);
    printf("Filho terminou com status %d\n", status);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe2a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x1c(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120c <main+0x4c>
lea    0xe08(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    128d <main+0xcd>
mov    -0x1c(%rbp),%edi
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    0x2bc2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bbf(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2bbc(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xdac(%rip),%rdi
call   10c0 <execvp@plt>
cmp    $0x0,%rax
jge    1288 <main+0xc8>
lea    0xdab(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
jmp    131b <main+0x15b>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
lea    0xd8e(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    0xd7c(%rip),%rsi
lea    0xd79(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rdi
lea    0xd65(%rip),%rsi
lea    0xd7c(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rdi
lea    0xd4e(%rip),%rsi
lea    0xd79(%rip),%rdx
call   1080 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
lea    -0x4c(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    -0x4c(%rbp),%esi
lea    0xd52(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1276 <main+0xb6>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     12d3 <main+0x113>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe28(%rip),%rsi
call   1090 <fdopen@plt>
mov    %rax,%rbx
lea    0xe1b(%rip),%r14
lea    0xe18(%rip),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
lea    0xe20(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
lea    0xe22(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    0x10(%rsp),%esi
lea    0xdf4(%rip),%rdi
call   1050 <printf@plt>
jmp    12c8 <main+0x108>
mov    0x8(%rsp),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x2b6f(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2b53(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xd51(%rip),%rdi
lea    0x10(%rsp),%rsi
call   10c0 <execvp@plt>
test   %rax,%rax
js     12dc <main+0x11c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd26(%rip),%rdi
jmp    12e3 <main+0x123>
lea    0xd3c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"adss\00"
@.str.1 = [10 x i8] c"Bad Fork!\00"
@STDIN_FILENO = global i32 0
@.str.2 = [7 x i8] c"python\00"
@.str.3 = [14 x i8] c"meu_script.py\00"
@__const.main.argv = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [9 x i8] c"Bad Exec\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [26 x i8] c"Minha terra tem palmeiras\00"
@.str.8 = [20 x i8] c"Onde canta o sabi\C3\A1\00"
@.str.9 = [7 x i8] c"<3 SOs\00"
@.str.10 = [30 x i8] c"Filho terminou com status %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [3 x i8*]
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %15
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%20 = load i32, i32* %19
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @dup2(i32 %20, i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = bitcast [3 x i8*]* %5 to i8*
%30 = getelementptr inbounds [3 x i8*], [3 x i8*]* %5, i64 0, i64 0
%31 = call i64 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %30)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %18
%34 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %18
br label %59
37: ; preds = %15
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32* @fdopen(i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %43, i32** %6
%44 = load i32*, i32** %6
%45 = call i32 @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32*, i32** %6
%47 = call i32 @fprintf(i32* %46, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%48 = load i32*, i32** %6
%49 = call i32 @fprintf(i32* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %3
%56 = call i32 @waitpid(i32 %55, i32* %7, i32 0)
%57 = load i32, i32* %7
%58 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %57)
br label %59
59: ; preds = %37, %36
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"Bad Fork!\00"
@STDIN_FILENO = global i32 0
@.str.2 = [7 x i8] c"python\00"
@.str.3 = [14 x i8] c"meu_script.py\00"
@__const.main.argv = [3 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [9 x i8] c"Bad Exec\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [26 x i8] c"Minha terra tem palmeiras\00"
@.str.8 = [20 x i8] c"Onde canta o sabi\C3\A1\00"
@.str.9 = [7 x i8] c"<3 SOs\00"
@.str.10 = [30 x i8] c"Filho terminou com status %d\0A\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [3 x i8*]
%3 = alloca i32
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
switch i32 %7, label %28 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = load i32, i32* %5
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @dup2(i32 %12, i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %5
%19 = call i32 @close(i32 %18)
%20 = bitcast [3 x i8*]* %2 to i8*
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%22 = call i64 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %11
br label %44
28: ; preds = %0
%29 = load i32, i32* %5
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32* @fdopen(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0))
%36 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%37 = call i32 @fclose(i32* %33)
%38 = load i32, i32* %31
%39 = call i32 @close(i32 %38)
%40 = bitcast i32* %3 to i8*
%41 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%42 = load i32, i32* %3
%43 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %28, %27
ret i32 0
}