#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*/ buff;

/* Variables and functions */
int close(int);
int dup(int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int read(int, char *, int);
int write(int, char *, int);
sortinvoke() {
  int pfdout[2], pfdin[2], fd, nread;
  char buff[512];
  if (pipe(pfdout) == -1 || pipe(pfdin) == -1) {
    perror("pipe");
    exit(-1);
  }
  switch (fork()) {
  case -1:
    perror("fork");
    exit(-1);
  case 0:
    if (close(0) == -1)
      perror("close");
    if (dup(pfdout[0]) != 0) {
      perror("dup");
      exit(-2);
    }
    if (close(1) == -1)
      perror("close");
    if (dup(pfdin[1]) != 1) {
      perror("dup2");
      exit(-3);
    }
    if (close(pfdout[0]) == -1 || close(pfdout[1]) == -1 ||
        close(pfdin[0]) == -1 || close(pfdin[1]) == -1)
      perror("close");
    execlp("sort", "sort", NULL);
    perror("execlp");
    exit(-4);
  default:
    break;
  }
  if (close(pfdout[0]) == -1 || close(pfdin[1]) == -1)
    perror("close");
  if ((fd = open("sortdata.txt", 0)) == -1)
    perror("open");
  while ((nread = read(fd, buff, sizeof(buff))) != 0) {
    if (nread == 1)
      perror("read");
    if (write(pfdout[1], buff, nread) == -1)
      perror("write");
  }
  if (close(fd) == -1 || close(pfdout[1]) == -1)
    perror("close");
  while ((nread = read(pfdin[0], buff, sizeof(buff))) != 0) {
    if (nread == -1)
      perror("read");
    if (write(1, buff, nread) == -1)
      perror("write");
  }
  if (close(pfdin[0]) == -1)
    perror("close");
}


x86 assembly (clang, -O0):
<sortinvoke>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11cf <sortinvoke+0x2f>
lea    -0x14(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11e5 <sortinvoke+0x45>
lea    0xe2a(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x224(%rbp)
sub    $0xffffffff,%eax
je     1215 <sortinvoke+0x75>
jmp    1202 <sortinvoke+0x62>
mov    -0x224(%rbp),%eax
test   %eax,%eax
je     122b <sortinvoke+0x8b>
jmp    132d <sortinvoke+0x18d>
lea    0xde9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
xor    %edi,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1247 <sortinvoke+0xa7>
lea    0xdc8(%rip),%rdi
call   1090 <perror@plt>
mov    -0xc(%rbp),%edi
call   1040 <dup@plt>
cmp    $0x0,%eax
je     126e <sortinvoke+0xce>
lea    0xdb1(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>
mov    $0x1,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    128d <sortinvoke+0xed>
lea    0xd82(%rip),%rdi
call   1090 <perror@plt>
mov    -0x10(%rbp),%edi
call   1040 <dup@plt>
cmp    $0x1,%eax
je     12b4 <sortinvoke+0x114>
lea    0xd6f(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffd,%edi
call   10a0 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12f8 <sortinvoke+0x158>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12f8 <sortinvoke+0x158>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12f8 <sortinvoke+0x158>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1304 <sortinvoke+0x164>
lea    0xd0b(%rip),%rdi
call   1090 <perror@plt>
lea    0xd0e(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10b0 <execlp@plt>
lea    0xd00(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffc,%edi
call   10a0 <exit@plt>
jmp    1332 <sortinvoke+0x192>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     1354 <sortinvoke+0x1b4>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1360 <sortinvoke+0x1c0>
lea    0xcaf(%rip),%rdi
call   1090 <perror@plt>
lea    0xcbe(%rip),%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1386 <sortinvoke+0x1e6>
lea    0xcb1(%rip),%rdi
call   1090 <perror@plt>
jmp    138b <sortinvoke+0x1eb>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     13ed <sortinvoke+0x24d>
cmpl   $0x1,-0x1c(%rbp)
jne    13c1 <sortinvoke+0x221>
lea    0xc7b(%rip),%rdi
call   1090 <perror@plt>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13e8 <sortinvoke+0x248>
lea    0xc59(%rip),%rdi
call   1090 <perror@plt>
jmp    138b <sortinvoke+0x1eb>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     140f <sortinvoke+0x26f>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    141b <sortinvoke+0x27b>
lea    0xbf4(%rip),%rdi
call   1090 <perror@plt>
jmp    1420 <sortinvoke+0x280>
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1484 <sortinvoke+0x2e4>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1456 <sortinvoke+0x2b6>
lea    0xbe6(%rip),%rdi
call   1090 <perror@plt>
lea    -0x220(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    147f <sortinvoke+0x2df>
lea    0xbc2(%rip),%rdi
call   1090 <perror@plt>
jmp    1420 <sortinvoke+0x280>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    14a1 <sortinvoke+0x301>
lea    0xb6e(%rip),%rdi
call   1090 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sortinvoke>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     12d3 <sortinvoke+0x133>
mov    %rsp,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     12d3 <sortinvoke+0x133>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     12df <sortinvoke+0x13f>
cmp    $0xffffffff,%eax
je     139f <sortinvoke+0x1ff>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12b1 <sortinvoke+0x111>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12b1 <sortinvoke+0x111>
lea    0xe0f(%rip),%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     12c2 <sortinvoke+0x122>
lea    0x10(%rsp),%rbx
lea    0xe02(%rip),%r15
lea    0xe00(%rip),%r14
nopl   0x0(%rax)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
je     1278 <sortinvoke+0xd8>
test   %ebp,%ebp
je     1282 <sortinvoke+0xe2>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1240 <sortinvoke+0xa0>
mov    %r14,%rdi
call   1090 <perror@plt>
jmp    1240 <sortinvoke+0xa0>
mov    %r15,%rdi
call   1090 <perror@plt>
jmp    125b <sortinvoke+0xbb>
mov    %r12d,%edi
call   1050 <close@plt>
lea    0xd79(%rip),%rbx
cmp    $0xffffffff,%eax
je     13e1 <sortinvoke+0x241>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    13e9 <sortinvoke+0x249>
jmp    13e1 <sortinvoke+0x241>
lea    0xd52(%rip),%rdi
call   1090 <perror@plt>
jmp    120f <sortinvoke+0x6f>
lea    0xd69(%rip),%rdi
call   1090 <perror@plt>
jmp    1229 <sortinvoke+0x89>
lea    0xd26(%rip),%rdi
jmp    13a6 <sortinvoke+0x206>
xor    %edi,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    12f7 <sortinvoke+0x157>
lea    0xd18(%rip),%rdi
call   1090 <perror@plt>
mov    0x8(%rsp),%edi
call   1040 <dup@plt>
test   %eax,%eax
jne    13b5 <sortinvoke+0x215>
mov    $0x1,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1323 <sortinvoke+0x183>
lea    0xcec(%rip),%rdi
call   1090 <perror@plt>
mov    0x4(%rsp),%edi
call   1040 <dup@plt>
cmp    $0x1,%eax
jne    13cb <sortinvoke+0x22b>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     136c <sortinvoke+0x1cc>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     136c <sortinvoke+0x1cc>
mov    (%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     136c <sortinvoke+0x1cc>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    1378 <sortinvoke+0x1d8>
lea    0xc97(%rip),%rdi
call   1090 <perror@plt>
lea    0xc9a(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   10b0 <execlp@plt>
lea    0xc8e(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffc,%edi
call   10a0 <exit@plt>
lea    0xc5f(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xc54(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffe,%edi
call   10a0 <exit@plt>
lea    0xc42(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffd,%edi
call   10a0 <exit@plt>
mov    %rbx,%rdi
call   1090 <perror@plt>
lea    0x10(%rsp),%rbx
lea    0xc42(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1431 <sortinvoke+0x291>
test   %ebp,%ebp
je     1440 <sortinvoke+0x2a0>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1400 <sortinvoke+0x260>
jmp    143b <sortinvoke+0x29b>
mov    %r15,%rdi
call   1090 <perror@plt>
jmp    141b <sortinvoke+0x27b>
mov    %r14,%rbx
jmp    13e1 <sortinvoke+0x241>
mov    (%rsp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     145d <sortinvoke+0x2bd>
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xba6(%rip),%rdi
call   1090 <perror@plt>
jmp    144d <sortinvoke+0x2ad>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [6 x i8] c"close\00"
@.str.3 = [4 x i8] c"dup\00"
@.str.4 = [5 x i8] c"dup2\00"
@.str.5 = [5 x i8] c"sort\00"
@.str.6 = [7 x i8] c"execlp\00"
@.str.7 = [13 x i8] c"sortdata.txt\00"
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [6 x i8] c"write\00"
define i32 @sortinvoke() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca [512 x i8]
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %10, %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
%18 = call i32 (...) @fork()
switch i32 %18, label %74 [
i32 -1, label %19
i32 0, label %22
]
19: ; preds = %17
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %17
%23 = call i32 @close(i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%29 = load i32, i32* %28
%30 = call i32 @dup(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -2)
unreachable
35: ; preds = %27
%36 = call i32 @close(i32 1)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %35
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @dup(i32 %42)
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @exit(i32 -3)
unreachable
48: ; preds = %40
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %68, label %53
53: ; preds = %48
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %68, label %58
58: ; preds = %53
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %68, label %63
63: ; preds = %58
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 @close(i32 %65)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %63, %58, %53, %48
%69 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %70
70: ; preds = %68, %63
%71 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* null)
%72 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%73 = call i32 @exit(i32 -4)
unreachable
74: ; preds = %17
br label %75
75: ; preds = %74
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%77 = load i32, i32* %76
%78 = call i32 @close(i32 %77)
%79 = icmp eq i32 %78, -1
br i1 %79, label %85, label %80
80: ; preds = %75
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %87
85: ; preds = %80, %75
%86 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %87
87: ; preds = %85, %80
%88 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 0)
store i32 %88, i32* %4
%89 = icmp eq i32 %88, -1
br i1 %89, label %90, label %92
90: ; preds = %87
%91 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %92
92: ; preds = %90, %87
br label %93
93: ; preds = %112, %92
%94 = load i32, i32* %4
%95 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%96 = call i32 @read(i32 %94, i8* %95, i32 512)
store i32 %96, i32* %5
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %113
98: ; preds = %93
%99 = load i32, i32* %5
%100 = icmp eq i32 %99, 1
br i1 %100, label %101, label %103
101: ; preds = %98
%102 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %103
103: ; preds = %101, %98
%104 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%105 = load i32, i32* %104
%106 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%107 = load i32, i32* %5
%108 = call i32 @write(i32 %105, i8* %106, i32 %107)
%109 = icmp eq i32 %108, -1
br i1 %109, label %110, label %112
110: ; preds = %103
%111 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %112
112: ; preds = %110, %103
br label %93
113: ; preds = %93
%114 = load i32, i32* %4
%115 = call i32 @close(i32 %114)
%116 = icmp eq i32 %115, -1
br i1 %116, label %122, label %117
117: ; preds = %113
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%119 = load i32, i32* %118
%120 = call i32 @close(i32 %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %124
122: ; preds = %117, %113
%123 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %124
124: ; preds = %122, %117
br label %125
125: ; preds = %143, %124
%126 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%127 = load i32, i32* %126
%128 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%129 = call i32 @read(i32 %127, i8* %128, i32 512)
store i32 %129, i32* %5
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %144
131: ; preds = %125
%132 = load i32, i32* %5
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %136
134: ; preds = %131
%135 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %136
136: ; preds = %134, %131
%137 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%138 = load i32, i32* %5
%139 = call i32 @write(i32 1, i8* %137, i32 %138)
%140 = icmp eq i32 %139, -1
br i1 %140, label %141, label %143
141: ; preds = %136
%142 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %143
143: ; preds = %141, %136
br label %125
144: ; preds = %125
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%146 = load i32, i32* %145
%147 = call i32 @close(i32 %146)
%148 = icmp eq i32 %147, -1
br i1 %148, label %149, label %151
149: ; preds = %144
%150 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %151
151: ; preds = %149, %144
%152 = load i32, i32* %1
ret i32 %152
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [6 x i8] c"close\00"
@.str.3 = [4 x i8] c"dup\00"
@.str.4 = [5 x i8] c"dup2\00"
@.str.5 = [5 x i8] c"sort\00"
@.str.6 = [7 x i8] c"execlp\00"
@.str.7 = [13 x i8] c"sortdata.txt\00"
@.str.8 = [5 x i8] c"open\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [6 x i8] c"write\00"
define i32 @sortinvoke() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [512 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast [2 x i32]* %2 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %10, %0
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %10
%18 = call i32 (...) @fork()
switch i32 %18, label %70 [
i32 -1, label %19
i32 0, label %22
]
19: ; preds = %17
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %17
%23 = call i32 @close(i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %7
%29 = call i32 @dup(i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = call i32 @perror(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 -2)
unreachable
34: ; preds = %27
%35 = call i32 @close(i32 1)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %34
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%41 = load i32, i32* %40
%42 = call i32 @dup(i32 %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %47, label %44
44: ; preds = %39
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 -3)
unreachable
47: ; preds = %39
%48 = load i32, i32* %7
%49 = call i32 @close(i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %64, label %51
51: ; preds = %47
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %64, label %56
56: ; preds = %51
%57 = load i32, i32* %11
%58 = call i32 @close(i32 %57)
%59 = icmp eq i32 %58, -1
br i1 %59, label %64, label %60
60: ; preds = %56
%61 = load i32, i32* %40
%62 = call i32 @close(i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %60, %56, %51, %47
%65 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
%67 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32* null)
%68 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%69 = call i32 @exit(i32 -4)
unreachable
70: ; preds = %17
%71 = load i32, i32* %7
%72 = call i32 @close(i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %79, label %74
74: ; preds = %70
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %74, %70
%80 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %81
81: ; preds = %79, %74
%82 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i32 0)
%83 = icmp eq i32 %82, -1
br i1 %83, label %84, label %86
84: ; preds = %81
%85 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %86
86: ; preds = %84, %81
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
br label %88
88: ; preds = %98, %86
%89 = call i32 @read(i32 %82, i8* %6, i32 512)
switch i32 %89, label %92 [
i32 0, label %99
i32 1, label %90
]
90: ; preds = %88
%91 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %92
92: ; preds = %88, %90
%93 = load i32, i32* %87
%94 = call i32 @write(i32 %93, i8* %6, i32 %89)
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %98
96: ; preds = %92
%97 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
br label %98
98: ; preds = %96, %92
br label %88
99: ; preds = %88
%100 = call i32 @close(i32 %82)
%101 = icmp eq i32 %100, -1
br i1 %101, label %106, label %102
102: ; preds = %99
%103 = load i32, i32* %87
%104 = call i32 @close(i32 %103)
%105 = icmp eq i32 %104, -1
br i1 %105, label %106, label %109
106: ; preds = %115, %99, %102
%107 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %102 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %99 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0), %115 ]
%108 = call i32 @perror(i8* %107)
br label %109
109: ; preds = %102, %106
br label %110
110: ; preds = %109, %115
%111 = load i32, i32* %11
%112 = call i32 @read(i32 %111, i8* %6, i32 512)
switch i32 %112, label %115 [
i32 0, label %118
i32 -1, label %113
]
113: ; preds = %110
%114 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %115
115: ; preds = %110, %113
%116 = call i32 @write(i32 1, i8* %6, i32 %112)
%117 = icmp eq i32 %116, -1
br i1 %117, label %106, label %110
118: ; preds = %110
%119 = load i32, i32* %11
%120 = call i32 @close(i32 %119)
%121 = icmp eq i32 %120, -1
br i1 %121, label %122, label %124
122: ; preds = %118
%123 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %124
124: ; preds = %122, %118
ret i32 undef
}