#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*/ AF_UNIX;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socketpair(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/,
               int *);
char toupper(char);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int sv[2];
  char buf;
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1) {
    perror("socketpair");
    exit(1);
  }
  if (!fork()) {
    read(sv[1], &buf, 1);
    printf("child: read '%c'\n", buf);
    buf = toupper(buf);
    write(sv[1], &buf, 1);
    printf("child: sent '%c'\n", buf);
  } else {
    write(sv[0], "b", 1);
    printf("parent: sent 'b'\n");
    read(sv[0], &buf, 1);
    printf("parent: read '%c'\n", buf);
    wait(NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rcx
xor    %edx,%edx
call   1070 <socketpair@plt>
cmp    $0xffffffff,%eax
jne    11db <main+0x4b>
lea    0xe34(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
cmp    $0x0,%eax
jne    1242 <main+0xb2>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0xd(%rbp),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movsbl -0xd(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movsbl -0xd(%rbp),%esi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1290 <main+0x100>
mov    -0xc(%rbp),%edi
lea    0xde3(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
movsbl -0xd(%rbp),%esi
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   1080 <socketpair@plt>
cmp    $0xffffffff,%eax
je     128f <main+0xef>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     122a <main+0x8a>
mov    0x8(%rsp),%edi
lea    0xe4a(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%esi
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <wait@plt>
jmp    1284 <main+0xe4>
mov    0xc(%rsp),%edi
lea    0x7(%rsp),%r14
mov    %r14,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
movsbl 0x7(%rsp),%ebp
lea    0xdbf(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1030 <toupper@plt>
mov    %eax,%ebx
mov    %al,0x7(%rsp)
mov    0xc(%rsp),%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
movsbl %bl,%esi
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd6a(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [18 x i8] c"child: read '%c'\0A\00"
@.str.2 = [18 x i8] c"child: sent '%c'\0A\00"
@.str.3 = [2 x i8] c"b\00"
@.str.4 = [18 x i8] c"parent: sent 'b'\0A\00"
@.str.5 = [19 x i8] c"parent: read '%c'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i8
store i32 0, i32* %1
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @socketpair(i32 %4, i32 %5, i32 0, i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 (...) @fork()
%14 = icmp ne i32 %13, 0
br i1 %14, label %30, label %15
15: ; preds = %12
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @read(i32 %17, i8* %3, i32 1)
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i8, i8* %3
%23 = call signext i8 @toupper(i8 signext %22)
store i8 %23, i8* %3
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @write(i32 %25, i8* %3, i32 1)
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %42
30: ; preds = %12
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @write(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @read(i32 %36, i8* %3, i32 1)
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = call i32 @wait(i32* null)
br label %42
42: ; preds = %30, %15
ret i32 0
}

LLVM IR (-O2):
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@.str = [11 x i8] c"socketpair\00"
@.str.1 = [18 x i8] c"child: read '%c'\0A\00"
@.str.2 = [18 x i8] c"child: sent '%c'\0A\00"
@.str.3 = [2 x i8] c"b\00"
@.str.5 = [19 x i8] c"parent: read '%c'\0A\00"
@str = [17 x i8] c"parent: sent 'b'\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i8
%3 = bitcast [2 x i32]* %1 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_STREAM
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%7 = call i32 @socketpair(i32 %4, i32 %5, i32 0, i32* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @read(i32 %17, i8* %2, i32 1)
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call signext i8 @toupper(i8 signext %19)
store i8 %22, i8* %2
%23 = load i32, i32* %16
%24 = call i32 @write(i32 %23, i8* %2, i32 1)
%25 = sext i8 %22 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %37
27: ; preds = %12
%28 = load i32, i32* %6
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%31 = load i32, i32* %6
%32 = call i32 @read(i32 %31, i8* %2, i32 1)
%33 = load i8, i8* %2
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = call i32 @wait(i32* null)
br label %37
37: ; preds = %27, %15
ret i32 0
}