#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 read(int, char *, int);
scalar_t__ strcmp(char *, char *);
void *parallel_read(void *arg) {
  int fd = (int)(long)arg;
  int i, rc;
  char buf[1024];
  for (i = 0; i < 3; i++) {
    rc = read(fd, buf, 4);
    if (rc <= 0)
      return NULL;
    buf[rc] = 0;
  }
  if (strcmp(buf, "w00t") == 0)
    return (void *)0x666;
  return NULL;
}


x86 assembly (clang, -O0):
<parallel_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    118f <parallel_read+0x6f>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x4,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jg     1175 <parallel_read+0x55>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <parallel_read+0xa2>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113d <parallel_read+0x1d>
lea    -0x420(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <parallel_read+0x9a>
mov    $0x666,%eax
mov    %rax,-0x8(%rbp)
jmp    11c2 <parallel_read+0xa2>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallel_read>:
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    1193 <parallel_read+0x73>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    1193 <parallel_read+0x73>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <read@plt>
test   %eax,%eax
jle    1193 <parallel_read+0x73>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe85(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x666,%eax
cmovne %rcx,%rax
jmp    1195 <parallel_read+0x75>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"w00t\00"
define i8* @parallel_read(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = ptrtoint i8* %8 to i64
%10 = trunc i64 %9 to i32
store i32 %10, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %25, %1
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = load i32, i32* %4
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 4)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i8* null, i8** %2
br label %34
21: ; preds = %14
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %21
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %11
28: ; preds = %11
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i8* inttoptr (i64 1638 to i8*), i8** %2
br label %34
33: ; preds = %28
store i8* null, i8** %2
br label %34
34: ; preds = %33, %32, %20
%35 = load i8*, i8** %2
ret i8* %35
}

LLVM IR (-O2):
@.str = [5 x i8] c"w00t\00"
define i8* @parallel_read(i8* %0) {
%2 = alloca [1024 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 4)
%7 = icmp slt i32 %6, 1
br i1 %7, label %24, label %8
8: ; preds = %1
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @read(i32 %4, i8* %5, i32 4)
%12 = icmp slt i32 %11, 1
br i1 %12, label %24, label %13
13: ; preds = %8
%14 = zext i32 %11 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @read(i32 %4, i8* %5, i32 4)
%17 = icmp slt i32 %16, 1
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = zext i32 %16 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i8* inttoptr (i64 1638 to i8*), i8* null
br label %24
24: ; preds = %1, %8, %13, %18
%25 = phi i8* [ %23, %18 ], [ null, %13 ], [ null, %8 ], [ null, %1 ]
ret i8* %25
}