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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ pthread_exit(int *);
int pthread_self();
int read(int, char *, int);
char *strerror(int /*<<< orphan*/);
void *test_read_null_hello_world(void *arg) {
  int id = pthread_self(), retval = 0;
  int fd, copied;
  char readed[20];
  fd = open("/dev/mynull", O_RDONLY);
  if (fd < 0) {
    printf("open /dev/mynull is not possible, %s.\n", strerror(errno));
    retval = -1;
    pthread_exit(&retval);
  }
  copied = read(fd, readed, 2);
  if (copied != 2) {
    printf("Can't read 2 char's\n");
    close(fd);
    retval = -1;
    pthread_exit(&retval);
  }
  printf("%d: readed char's: %s\n", id, readed);
  memset(readed, 0, sizeof(readed));
  copied = read(fd, readed, 3);
  if (copied != 3) {
    printf("Can't read 2 char's\n");
    close(fd);
    retval = -1;
    pthread_exit(&retval);
  }
  printf("%d: readed char's: %s\n", id, readed);
  memset(readed, 0, sizeof(readed));
  copied = read(fd, readed, 6);
  if (copied != 6) {
    printf("Can't read 2 char's\n");
    close(fd);
    retval = -1;
    pthread_exit(&retval);
  }
  printf("%d: readed char's: %s\n", id, readed);
  memset(readed, 0, sizeof(readed));
  copied = read(fd, readed, 6);
  printf("%d: readed char's: %s\n", id, readed);
  memset(readed, 0, sizeof(readed));
  copied = read(fd, readed, 6);
  printf("%d: readed char's: %s\n", id, readed);
  memset(readed, 0, sizeof(readed));
  close(fd);
  pthread_exit(&retval);
}


x86 assembly (clang, -O0):
<test_read_null_hello_world>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <pthread_self@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11ee <test_read_null_hello_world+0x6e>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,%rsi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pthread_exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x2,-0x20(%rbp)
je     1232 <test_read_null_hello_world+0xb2>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pthread_exit@plt>
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
je     129b <test_read_null_hello_world+0x11b>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pthread_exit@plt>
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xd9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x6,-0x20(%rbp)
je     1304 <test_read_null_hello_world+0x184>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pthread_exit@plt>
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xd36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
lea    0xcc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_null_hello_world>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
xor    %eax,%eax
call   1090 <pthread_self@plt>
mov    %eax,%r14d
movl   $0x0,0xc(%rsp)
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
lea    0xe44(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11f8 <test_read_null_hello_world+0x68>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xe30(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdi
call   1080 <pthread_exit@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1070 <read@plt>
cmp    $0x2,%eax
je     1233 <test_read_null_hello_world+0xa3>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdi
call   1080 <pthread_exit@plt>
lea    0xdf9(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %r14d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1070 <read@plt>
cmp    $0x3,%eax
je     1294 <test_read_null_hello_world+0x104>
lea    0xdd4(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdi
call   1080 <pthread_exit@plt>
lea    0xd98(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %r14d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
cmp    $0x6,%eax
je     12f5 <test_read_null_hello_world+0x165>
lea    0xd73(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rdi
call   1080 <pthread_exit@plt>
lea    0xd37(%rip),%r15
lea    0x10(%rsp),%rbp
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1070 <read@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1050 <memset@plt>
mov    %ebx,%edi
call   1060 <close@plt>
lea    0xc(%rsp),%rdi
call   1080 <pthread_exit@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/mynull\00"
@O_RDONLY = global i32 0
@.str.1 = [39 x i8] c"open /dev/mynull is not possible, %s.\0A\00"
@errno = global i32 0
@.str.2 = [21 x i8] c"Can't read 2 char's\0A\00"
@.str.3 = [23 x i8] c"%d: readed char's: %s\0A\00"
define i8* @test_read_null_hello_world(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [20 x i8]
store i8* %0, i8** %3
%9 = call i32 (...) @pthread_self()
store i32 %9, i32* %4
store i32 0, i32* %5
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %1
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 -1, i32* %5
%18 = call i32 @pthread_exit(i32* %5)
br label %19
19: ; preds = %14, %1
%20 = load i32, i32* %6
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%22 = call i32 @read(i32 %20, i8* %21, i32 2)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 2
br i1 %24, label %25, label %30
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %5
%29 = call i32 @pthread_exit(i32* %5)
br label %30
30: ; preds = %25, %19
%31 = load i32, i32* %4
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %31, i8* %32)
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 20)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 3)
store i32 %38, i32* %7
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 3
br i1 %40, label %41, label %46
41: ; preds = %30
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 -1, i32* %5
%45 = call i32 @pthread_exit(i32* %5)
br label %46
46: ; preds = %41, %30
%47 = load i32, i32* %4
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %47, i8* %48)
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%51 = call i32 @memset(i8* %50, i32 0, i32 20)
%52 = load i32, i32* %6
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 6)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp ne i32 %55, 6
br i1 %56, label %57, label %62
57: ; preds = %46
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* %6
%60 = call i32 @close(i32 %59)
store i32 -1, i32* %5
%61 = call i32 @pthread_exit(i32* %5)
br label %62
62: ; preds = %57, %46
%63 = load i32, i32* %4
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %63, i8* %64)
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%67 = call i32 @memset(i8* %66, i32 0, i32 20)
%68 = load i32, i32* %6
%69 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%70 = call i32 @read(i32 %68, i8* %69, i32 6)
store i32 %70, i32* %7
%71 = load i32, i32* %4
%72 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %71, i8* %72)
%74 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i32 0, i32 20)
%76 = load i32, i32* %6
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 6)
store i32 %78, i32* %7
%79 = load i32, i32* %4
%80 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %79, i8* %80)
%82 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%83 = call i32 @memset(i8* %82, i32 0, i32 20)
%84 = load i32, i32* %6
%85 = call i32 @close(i32 %84)
%86 = call i32 @pthread_exit(i32* %5)
%87 = load i8*, i8** %2
ret i8* %87
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/mynull\00"
@O_RDONLY = global i32 0
@.str.1 = [39 x i8] c"open /dev/mynull is not possible, %s.\0A\00"
@errno = global i32 0
@.str.3 = [23 x i8] c"%d: readed char's: %s\0A\00"
@str.5 = [20 x i8] c"Can't read 2 char's\00"
define noalias i8* @test_read_null_hello_world(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = tail call i32 (...) @pthread_self()
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32 -1, i32* %2
%14 = call i32 @pthread_exit(i32* %2)
br label %15
15: ; preds = %10, %1
%16 = call i32 @read(i32 %8, i8* %6, i32 2)
%17 = icmp eq i32 %16, 2
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%20 = call i32 @close(i32 %8)
store i32 -1, i32* %2
%21 = call i32 @pthread_exit(i32* %2)
br label %22
22: ; preds = %18, %15
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %6)
%24 = call i32 @memset(i8* %6, i32 0, i32 20)
%25 = call i32 @read(i32 %8, i8* %6, i32 3)
%26 = icmp eq i32 %25, 3
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%29 = call i32 @close(i32 %8)
store i32 -1, i32* %2
%30 = call i32 @pthread_exit(i32* %2)
br label %31
31: ; preds = %27, %22
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %6)
%33 = call i32 @memset(i8* %6, i32 0, i32 20)
%34 = call i32 @read(i32 %8, i8* %6, i32 6)
%35 = icmp eq i32 %34, 6
br i1 %35, label %40, label %36
36: ; preds = %31
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%38 = call i32 @close(i32 %8)
store i32 -1, i32* %2
%39 = call i32 @pthread_exit(i32* %2)
br label %40
40: ; preds = %36, %31
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %6)
%42 = call i32 @memset(i8* %6, i32 0, i32 20)
%43 = call i32 @read(i32 %8, i8* %6, i32 6)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %6)
%45 = call i32 @memset(i8* %6, i32 0, i32 20)
%46 = call i32 @read(i32 %8, i8* %6, i32 6)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i8* %6)
%48 = call i32 @memset(i8* %6, i32 0, i32 20)
%49 = call i32 @close(i32 %8)
%50 = call i32 @pthread_exit(i32* %2)
ret i8* undef
}