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

/* Variables and functions */
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ chroot(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int fd[2];
  char buf1[2] = "a";
  char buf2[2];
  close(-1);
  chroot(".");
  pipe(fd);
  write(fd[1], buf1, sizeof(buf1));
  read(fd[0], buf2, sizeof(buf2));
  _exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%ax
mov    %ax,-0xe(%rbp)
mov    $0xffffffff,%edi
call   1060 <close@plt>
lea    0xe77(%rip),%rdi
call   1040 <chroot@plt>
lea    -0xc(%rbp),%rdi
call   1070 <pipe@plt>
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x2,%edx
call   1080 <read@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movw   $0x61,0xc(%rsp)
mov    $0xffffffff,%edi
call   1060 <close@plt>
lea    0xe84(%rip),%rdi
call   1040 <chroot@plt>
lea    0x10(%rsp),%rdi
call   1070 <pipe@plt>
mov    0x14(%rsp),%edi
lea    0xc(%rsp),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    0x10(%rsp),%edi
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
call   1080 <read@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@__const.main.buf1 = [2 x i8] c"a\00"
@.str = [2 x i8] c".\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i8]
%4 = alloca [2 x i8]
store i32 0, i32* %1
%5 = bitcast [2 x i8]* %3 to i8*
%6 = call i32 @close(i32 -1)
%7 = call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%13 = call i32 @write(i32 %11, i8* %12, i32 2)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 2)
%18 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca i16
%3 = alloca [2 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast i16* %2 to i8*
store i16 97, i16* %2
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @close(i32 -1)
%8 = tail call i32 @chroot(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @write(i32 %12, i8* %5, i32 2)
%14 = load i32, i32* %9
%15 = call i32 @read(i32 %14, i8* %6, i32 2)
%16 = call i32 @_exit(i32 0)
unreachable
}