#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ invertCase(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Wrong number of arguments\n");
    printf("please use: ./binary 'String'\n");
    exit(1);
  }
  int pipeFds1[2];
  int pipeFds2[2];
  char *buffer = 0;
  int inputSize = 0;
  if (pipe(pipeFds1) < 0 || pipe(pipeFds2) < 0) {
    perror("pipe");
    exit(1);
  }
  inputSize = strlen(argv[1]);
  if (!fork()) {
    close(pipeFds1[1]);
    close(pipeFds2[0]);
    if (!(buffer = malloc(sizeof(char) * inputSize))) {
      perror("malloc");
      exit(1);
    }
    read(pipeFds1[0], buffer, inputSize);
    printf("Received (Child): %s\n", buffer);
    invertCase(buffer);
    write(pipeFds2[1], buffer, inputSize);
    free(buffer);
    exit(0);
  } else {
    close(pipeFds1[0]);
    close(pipeFds2[1]);
    write(pipeFds1[1], argv[1], inputSize);
    if (!(buffer = malloc(sizeof(char) * inputSize))) {
      perror("malloc");
      exit(1);
    }
    read(pipeFds2[0], buffer, inputSize);
    wait(NULL);
    printf("The new string (Parent): %s\n", buffer);
    free(buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1216 <main+0x46>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
lea    -0x18(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jl     124b <main+0x7b>
lea    -0x20(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    1261 <main+0x91>
lea    0xde8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   10f0 <fork@plt>
cmp    $0x0,%eax
jne    130d <main+0x13d>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x20(%rbp),%edi
call   1070 <close@plt>
movslq -0x2c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12c4 <main+0xf4>
lea    0xd8a(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1090 <read@plt>
mov    -0x28(%rbp),%rsi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <invertCase@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <write@plt>
movslq -0x2c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1363 <main+0x193>
lea    0xceb(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1090 <read@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
mov    -0x28(%rbp),%rsi
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    12a6 <main+0xc6>
mov    %rsi,%rbx
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
js     129d <main+0xbd>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
js     129d <main+0xbd>
mov    0x8(%rbx),%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     12c8 <main+0xe8>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
mov    0x14(%rsp),%edi
mov    0x8(%rbx),%rsi
mov    %ebp,%edx
call   1050 <write@plt>
mov    %ebp,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
je     12e6 <main+0x106>
mov    %rax,%rbx
mov    0x8(%rsp),%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   10a0 <read@plt>
xor    %edi,%edi
call   10f0 <wait@plt>
lea    0xda0(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd5c(%rip),%rdi
jmp    12ed <main+0x10d>
lea    0xd92(%rip),%rdi
call   1040 <puts@plt>
lea    0xda0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    %ebp,%edi
call   10c0 <malloc@plt>
test   %rax,%rax
jne    12fc <main+0x11c>
lea    0xd18(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %rax,%rbx
mov    0x10(%rsp),%edi
mov    %rax,%rsi
mov    %ebp,%edx
call   10a0 <read@plt>
lea    0xcf8(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10b0 <invertCase@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <write@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Wrong number of arguments\0A\00"
@.str.1 = [31 x i8] c"please use: ./binary 'String'\0A\00"
@.str.2 = [5 x i8] c"pipe\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [22 x i8] c"Received (Child): %s\0A\00"
@.str.5 = [29 x i8] c"The new string (Parent): %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i8* null, i8** %8
store i32 0, i32* %9
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%18 = call i64 @pipe(i32* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%22 = call i64 @pipe(i32* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20, %16
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %9
%32 = call i32 (...) @fork()
%33 = icmp ne i32 %32, 0
br i1 %33, label %68, label %34
34: ; preds = %27
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = mul i64 1, %42
%44 = trunc i64 %43 to i32
%45 = call i8* @malloc(i32 %44)
store i8* %45, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %50, label %47
47: ; preds = %34
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %34
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%52 = load i32, i32* %51
%53 = load i8*, i8** %8
%54 = load i32, i32* %9
%55 = call i32 @read(i32 %52, i8* %53, i32 %54)
%56 = load i8*, i8** %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = load i8*, i8** %8
%59 = call i32 @invertCase(i8* %58)
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%61 = load i32, i32* %60
%62 = load i8*, i8** %8
%63 = load i32, i32* %9
%64 = call i32 @write(i32 %61, i8* %62, i32 %63)
%65 = load i8*, i8** %8
%66 = call i32 @free(i8* %65)
%67 = call i32 @exit(i32 0)
unreachable
68: ; preds = %27
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%70 = load i32, i32* %69
%71 = call i32 @close(i32 %70)
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%73 = load i32, i32* %72
%74 = call i32 @close(i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%76 = load i32, i32* %75
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 1
%79 = load i8*, i8** %78
%80 = load i32, i32* %9
%81 = call i32 @write(i32 %76, i8* %79, i32 %80)
%82 = load i32, i32* %9
%83 = sext i32 %82 to i64
%84 = mul i64 1, %83
%85 = trunc i64 %84 to i32
%86 = call i8* @malloc(i32 %85)
store i8* %86, i8** %8
%87 = icmp ne i8* %86, null
br i1 %87, label %91, label %88
88: ; preds = %68
%89 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %68
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%93 = load i32, i32* %92
%94 = load i8*, i8** %8
%95 = load i32, i32* %9
%96 = call i32 @read(i32 %93, i8* %94, i32 %95)
%97 = call i32 @wait(i32* null)
%98 = load i8*, i8** %8
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %98)
%100 = load i8*, i8** %8
%101 = call i32 @free(i8* %100)
br label %102
102: ; preds = %91
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [5 x i8] c"pipe\00"
@.str.3 = [7 x i8] c"malloc\00"
@.str.4 = [22 x i8] c"Received (Child): %s\0A\00"
@.str.5 = [29 x i8] c"The new string (Parent): %s\0A\00"
@str = [26 x i8] c"Wrong number of arguments\00"
@str.6 = [30 x i8] c"please use: ./binary 'String'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast [2 x i32]* %3 to i8*
%12 = bitcast [2 x i32]* %4 to i8*
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%14 = call i64 @pipe(i32* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%18 = call i64 @pipe(i32* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %10
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
%27 = call i32 (...) @fork()
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %23
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %17
%34 = call i32 @close(i32 %33)
%35 = call i8* @malloc(i32 %26)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = load i32, i32* %13
%42 = call i32 @read(i32 %41, i8* %35, i32 %26)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%44 = call i32 @invertCase(i8* %35)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%46 = load i32, i32* %45
%47 = call i32 @write(i32 %46, i8* %35, i32 %26)
%48 = call i32 @free(i8* %35)
%49 = call i32 @exit(i32 0)
unreachable
50: ; preds = %23
%51 = load i32, i32* %13
%52 = call i32 @close(i32 %51)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%57 = load i32, i32* %56
%58 = load i8*, i8** %24
%59 = call i32 @write(i32 %57, i8* %58, i32 %26)
%60 = call i8* @malloc(i32 %26)
%61 = icmp eq i8* %60, null
br i1 %61, label %62, label %65
62: ; preds = %50
%63 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %50
%66 = load i32, i32* %17
%67 = call i32 @read(i32 %66, i8* %60, i32 %26)
%68 = call i32 @wait(i32* null)
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%70 = call i32 @free(i8* %60)
ret i32 0
}