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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int memcmp(char *, char *, int);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int testfd(int desc) {
  char buf[256];
  if (read(desc, buf, sizeof(buf)) != sizeof("test")) {
    fprintf(stderr, "test data not received correctly!");
    return 1;
  }
  return memcmp(buf, "test", sizeof("test"));
}


x86 assembly (clang, -O0):
<testfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1030 <read@plt>
cltq
cmp    $0x5,%rax
je     117f <testfd+0x4f>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    119a <testfd+0x6a>
lea    -0x110(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcmp@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testfd>:
sub    $0x108,%rsp
mov    %rsp,%rsi
mov    $0x100,%edx
call   1030 <read@plt>
cmp    $0x5,%eax
jne    1165 <testfd+0x35>
lea    0xed2(%rip),%rsi
mov    %rsp,%rdi
mov    $0x5,%edx
call   1040 <memcmp@plt>
add    $0x108,%rsp
ret
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x108,%rsp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [34 x i8] c"test data not received correctly!\00"
@.str.1 = [5 x i8] c"test\00"
define i32 @testfd(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 256)
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 5
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %2
br label %16
13: ; preds = %1
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%15 = call i32 @memcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
store i32 %15, i32* %2
br label %16
16: ; preds = %13, %10
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [34 x i8] c"test data not received correctly!\00"
@.str.1 = [5 x i8] c"test\00"
define i32 @testfd(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 256)
%5 = icmp eq i32 %4, 5
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i32 @memcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 5)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ 1, %6 ], [ %10, %9 ]
ret i32 %12
}