#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ log_printf(int, char *, ...);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int pipe_read(int pipe_fd[], char *getText) {
  close(pipe_fd[1]);
  if ((read(pipe_fd[0], getText, 10)) < 0) {
    log_printf(0, "Fehler beim Lesen der Pipe");
    perror("Error: ");
    return 0;
  }
  log_printf(2, "Pipe gelesen: %s\n", getText);
  return 1;
}


x86 assembly (clang, -O0):
<pipe_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jge    11a2 <pipe_read+0x62>
xor    %edi,%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <log_printf@plt>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c0 <pipe_read+0x80>
mov    -0x18(%rbp),%rdx
mov    $0x2,%edi
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <log_printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_read>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x4(%rdi),%edi
call   1030 <close@plt>
mov    (%rbx),%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
test   %rax,%rax
js     118b <pipe_read+0x4b>
lea    0xeb6(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <log_printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6e(%rip),%rsi
xor    %ebx,%ebx
xor    %edi,%edi
xor    %eax,%eax
call   1050 <log_printf@plt>
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
jmp    1181 <pipe_read+0x41>

LLVM IR (-O0):
@.str = [27 x i8] c"Fehler beim Lesen der Pipe\00"
@.str.1 = [8 x i8] c"Error: \00"
@.str.2 = [18 x i8] c"Pipe gelesen: %s\0A\00"
define i32 @pipe_read(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
%6 = load i32*, i32** %4
%7 = getelementptr inbounds i32, i32* %6, i64 1
%8 = load i32, i32* %7
%9 = call i32 @close(i32 %8)
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = load i8*, i8** %5
%14 = call i64 @read(i32 %12, i8* %13, i32 10)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 (i32, i8*, ...) @log_printf(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %22
19: ; preds = %2
%20 = load i8*, i8** %5
%21 = call i32 (i32, i8*, ...) @log_printf(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %20)
store i32 1, i32* %3
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [27 x i8] c"Fehler beim Lesen der Pipe\00"
@.str.1 = [8 x i8] c"Error: \00"
@.str.2 = [18 x i8] c"Pipe gelesen: %s\0A\00"
define i32 @pipe_read(i32* nocapture %0, i8* %1) {
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
%5 = tail call i32 @close(i32 %4)
%6 = load i32, i32* %0
%7 = tail call i64 @read(i32 %6, i8* %1, i32 10)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 (i32, i8*, ...) @log_printf(i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %2
%13 = tail call i32 (i32, i8*, ...) @log_printf(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %14
14: ; preds = %12, %9
%15 = phi i32 [ 0, %9 ], [ 1, %12 ]
ret i32 %15
}