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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, ...);
int open_files(int readfd) {
  char buff[256];
  int len, i, status;
  int tmpfd;
  for (i = 0; i < 3; i++) {
    memset(buff, 0, 256);
    status = read(readfd, &len, sizeof(len));
    if (status < 0) {
      printf("Could not read len from pipe, %d\n", status);
      goto bail;
    }
    status = read(readfd, buff, len);
    if (status < 0) {
      printf("Could not read buff from pipe, %d\n", status);
      goto bail;
    }
    tmpfd = open(buff, O_RDWR);
    if (tmpfd < 0) {
      status = tmpfd;
      printf("Could not open file \"%s\", %d", buff, tmpfd);
      goto bail;
    }
  }
bail:
  return (status);
}


x86 assembly (clang, -O0):
<open_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x118(%rbp)
cmpl   $0x3,-0x118(%rbp)
jge    126a <open_files+0x12a>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x114(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jge    11ba <open_files+0x7a>
mov    -0x11c(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <open_files+0x12f>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x114(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
mov    %eax,-0x11c(%rbp)
cmpl   $0x0,-0x11c(%rbp)
jge    11fd <open_files+0xbd>
mov    -0x11c(%rbp),%esi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <open_files+0x12f>
lea    -0x110(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x120(%rbp)
cmpl   $0x0,-0x120(%rbp)
jge    1251 <open_files+0x111>
mov    -0x120(%rbp),%eax
mov    %eax,-0x11c(%rbp)
lea    -0x110(%rbp),%rsi
mov    -0x120(%rbp),%edx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126f <open_files+0x12f>
jmp    1256 <open_files+0x116>
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
jmp    1158 <open_files+0x18>
jmp    126f <open_files+0x12f>
mov    -0x11c(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_files>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
js     1270 <open_files+0x130>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
js     127b <open_files+0x13b>
mov    0x2e4e(%rip),%r14
mov    (%r14),%esi
lea    0x10(%rsp),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1257 <open_files+0x117>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
js     1270 <open_files+0x130>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
js     127b <open_files+0x13b>
mov    (%r14),%esi
lea    0x10(%rsp),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1257 <open_files+0x117>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %eax,%eax
js     1270 <open_files+0x130>
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1050 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
js     127d <open_files+0x13d>
mov    (%r14),%esi
lea    0x10(%rsp),%rdi
call   1060 <open@plt>
test   %eax,%eax
jns    128d <open_files+0x14d>
mov    %eax,%ebp
lea    0xde5(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    128d <open_files+0x14d>
mov    %eax,%ebp
lea    0xd87(%rip),%rdi
jmp    1284 <open_files+0x144>
mov    %eax,%ebp
lea    0xd9e(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Could not read len from pipe, %d\0A\00"
@.str.1 = [35 x i8] c"Could not read buff from pipe, %d\0A\00"
@O_RDWR = global i32 0
@.str.2 = [29 x i8] c"Could not open file \22%s\22, %d\00"
define i32 @open_files(i32 %0) {
%2 = alloca i32
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %5
br label %8
8: ; preds = %43, %1
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %46
11: ; preds = %8
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 256)
%14 = load i32, i32* %2
%15 = call i32 (i32, ...) @read(i32 %14, i32* %4, i64 4)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %47
21: ; preds = %11
%22 = load i32, i32* %2
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* %4
%25 = call i32 (i32, ...) @read(i32 %22, i8* %23, i32 %24)
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i32, i32* %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %47
31: ; preds = %21
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = load i32, i32* @O_RDWR
%34 = call i32 @open(i8* %32, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %31
%38 = load i32, i32* %7
store i32 %38, i32* %6
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%40 = load i32, i32* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %39, i32 %40)
br label %47
42: ; preds = %31
br label %43
43: ; preds = %42
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %8
46: ; preds = %8
br label %47
47: ; preds = %46, %37, %28, %18
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
@.str = [34 x i8] c"Could not read len from pipe, %d\0A\00"
@.str.1 = [35 x i8] c"Could not read buff from pipe, %d\0A\00"
@O_RDWR = global i32 0
@.str.2 = [29 x i8] c"Could not open file \22%s\22, %d\00"
define i32 @open_files(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = call i32 @memset(i8* %4, i32 0, i32 256)
%7 = call i32 (i32, ...) @read(i32 %0, i32* %3, i64 4)
%8 = icmp slt i32 %7, 0
br i1 %8, label %33, label %36
9: ; preds = %43
%10 = call i32 @memset(i8* %4, i32 0, i32 256)
%11 = call i32 (i32, ...) @read(i32 %0, i32* %3, i64 4)
%12 = icmp slt i32 %11, 0
br i1 %12, label %33, label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 (i32, ...) @read(i32 %0, i8* %4, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %40, label %17
17: ; preds = %13
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* %4, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %47, label %21
21: ; preds = %17
%22 = call i32 @memset(i8* %4, i32 0, i32 256)
%23 = call i32 (i32, ...) @read(i32 %0, i32* %3, i64 4)
%24 = icmp slt i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i32, i32* %3
%27 = call i32 (i32, ...) @read(i32 %0, i8* %4, i32 %26)
%28 = icmp slt i32 %27, 0
br i1 %28, label %40, label %29
29: ; preds = %25
%30 = load i32, i32* @O_RDWR
%31 = call i32 @open(i8* %4, i32 %30)
%32 = icmp slt i32 %31, 0
br i1 %32, label %47, label %50
33: ; preds = %21, %9, %1
%34 = phi i32 [ %7, %1 ], [ %11, %9 ], [ %23, %21 ]
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %50
36: ; preds = %1
%37 = load i32, i32* %3
%38 = call i32 (i32, ...) @read(i32 %0, i8* %4, i32 %37)
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %25, %13, %36
%41 = phi i32 [ %38, %36 ], [ %15, %13 ], [ %27, %25 ]
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %50
43: ; preds = %36
%44 = load i32, i32* @O_RDWR
%45 = call i32 @open(i8* %4, i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %9
47: ; preds = %29, %17, %43
%48 = phi i32 [ %45, %43 ], [ %19, %17 ], [ %31, %29 ]
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 %48)
br label %50
50: ; preds = %29, %47, %40, %33
%51 = phi i32 [ %34, %33 ], [ %41, %40 ], [ %48, %47 ], [ %27, %29 ]
ret i32 %51
}