#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 dup(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void *read_fifo2(void *_fd) {
  int fd = dup((int)_fd);
  int ret;
  char read_buf[1024];
  if ((ret = read(fd, read_buf, 1024)) > 0) {
    do {
      if (4 <= 4) {
        fprintf(stderr,
                "%s %d: "
                "reader got: %s\n",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/"
                "master/fifo/main.c",
                35, read_buf);
      }
    } while (0);
  }
  close(fd);
  return NULL;
}


x86 assembly (clang, -O0):
<read_fifo2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1030 <dup@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    11af <read_fifo2+0x6f>
jmp    1182 <read_fifo2+0x42>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%r8
lea    0xe67(%rip),%rsi
lea    0xe77(%rip),%rdx
mov    $0x23,%ecx
call   1060 <fprintf@plt>
jmp    11af <read_fifo2+0x6f>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_fifo2>:
push   %rbx
sub    $0x400,%rsp
call   1030 <dup@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x400,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    1186 <read_fifo2+0x46>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
lea    0xe9e(%rip),%rdx
mov    %rsp,%r8
mov    $0x23,%ecx
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"%s %d: reader got: %s\0A\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/fifo/main.c\00"
define i8* @read_fifo2(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = ptrtoint i8* %6 to i32
%8 = call i32 @dup(i32 %7)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 1024)
store i32 %11, i32* %4
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %1
br label %14
14: ; preds = %13
%15 = load i32, i32* @stderr
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* %16)
br label %18
18: ; preds = %14
br label %19
19: ; preds = %18, %1
%20 = load i32, i32* %3
%21 = call i32 @close(i32 %20)
ret i8* null
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"%s %d: reader got: %s\0A\00"
@.str.1 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/clpsz/linux-ipcs/refs/heads/master/fifo/main.c\00"
define noalias i8* @read_fifo2(i8* %0) {
%2 = alloca [1024 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 @dup(i32 %4)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 1024)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* %6)
br label %12
12: ; preds = %9, %1
%13 = call i32 @close(i32 %5)
ret i8* null
}