#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 */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int read_notifications(char *, int);
int /*<<< orphan*/ stderr;
int receive_notifications(int fd) {
  char buf[1024];
  int bufptr;
  bufptr = 0;
  while (1) {
    int rc = read(fd, buf + bufptr, 1024 - bufptr);
    if (rc < 0) {
      if (errno == EINTR) {
        continue;
      } else {
        {
          {
            fprintf(stderr, "ERROR - %s - l.%d - ",
                    "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/bfontaine/Dazibao/refs/"
                    "heads/master/src/notifier/notification-client.c",
                    108);
            perror((("read")));
          };
          return (-1);
        };
      }
    }
    if (rc == 0) {
      break;
    }
    bufptr = read_notifications(buf, bufptr + rc);
    if (bufptr == -1) {
      {
        {
          fprintf(stderr, "ERROR - %s - l.%d - ",
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/bfontaine/Dazibao/refs/"
                  "heads/master/src/notifier/notification-client.c",
                  118);
          perror((("read_notifications")));
        };
        return (-1);
      };
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<receive_notifications>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x414(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x410(%rbp),%rsi
movslq -0x414(%rbp),%rax
add    %rax,%rsi
mov    $0x400,%edx
sub    -0x414(%rbp),%edx
call   1040 <read@plt>
mov    %eax,-0x418(%rbp)
cmpl   $0x0,-0x418(%rbp)
jge    11e7 <receive_notifications+0xa7>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
jne    11ae <receive_notifications+0x6e>
jmp    1158 <receive_notifications+0x18>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
lea    0xe50(%rip),%rdx
mov    $0x6c,%ecx
call   1050 <fprintf@plt>
lea    0xee0(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <receive_notifications+0x129>
cmpl   $0x0,-0x418(%rbp)
jne    11f9 <receive_notifications+0xb9>
jmp    1262 <receive_notifications+0x122>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
add    -0x418(%rbp),%esi
call   1030 <read_notifications@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    125d <receive_notifications+0x11d>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
lea    0xdda(%rip),%rdx
mov    $0x76,%ecx
call   1050 <fprintf@plt>
lea    0xe6f(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1269 <receive_notifications+0x129>
jmp    1158 <receive_notifications+0x18>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_notifications>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edi,%r13d
xor    %r12d,%r12d
mov    0x2e7a(%rip),%r14
mov    0x2e6b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movslq %r12d,%rax
lea    (%rsp,%rax,1),%rbx
mov    $0x400,%ebp
sub    %eax,%ebp
xchg   %ax,%ax
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <read@plt>
test   %eax,%eax
jns    11a0 <receive_notifications+0x60>
mov    (%r14),%rax
cmp    (%r15),%rax
je     1180 <receive_notifications+0x40>
jmp    11c5 <receive_notifications+0x85>
nopl   0x0(%rax,%rax,1)
je     11f5 <receive_notifications+0xb5>
add    %r12d,%eax
mov    %rsp,%rdi
mov    %eax,%esi
call   1030 <read_notifications@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    1170 <receive_notifications+0x30>
mov    $0x76,%ecx
lea    0xef8(%rip),%rbx
jmp    11d1 <receive_notifications+0x91>
mov    $0x6c,%ecx
lea    0xee5(%rip),%rbx
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
lea    0xe2d(%rip),%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR - %s - l.%d - \00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bfontaine/Dazibao/refs/heads/master/src/notifier/notification-client.c\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [19 x i8] c"read_notifications\00"
define i32 @receive_notifications(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
br label %7
7: ; preds = %1, %22, %43
%8 = load i32, i32* %3
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i32, i32* %5
%14 = sub nsw i32 1024, %13
%15 = call i32 @read(i32 %8, i8* %12, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %7
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %7
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 108)
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
27: ; preds = %7
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %44
31: ; preds = %27
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = load i32, i32* %5
%34 = load i32, i32* %6
%35 = add nsw i32 %33, %34
%36 = call i32 @read_notifications(i8* %32, i32 %35)
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 118)
%42 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
43: ; preds = %31
br label %7
44: ; preds = %30
store i32 -1, i32* %2
br label %45
45: ; preds = %44, %39, %23
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"ERROR - %s - l.%d - \00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/bfontaine/Dazibao/refs/heads/master/src/notifier/notification-client.c\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [19 x i8] c"read_notifications\00"
define i32 @receive_notifications(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %18, %1
%5 = phi i32 [ %20, %18 ], [ 0, %1 ]
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %6
%8 = sub nsw i32 1024, %5
br label %9
9: ; preds = %4, %12
%10 = call i32 @read(i32 %0, i8* %7, i32 %8)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
br i1 %15, label %9, label %22
16: ; preds = %9
%17 = icmp eq i32 %10, 0
br i1 %17, label %28, label %18
18: ; preds = %16
%19 = add nsw i32 %10, %5
%20 = call i32 @read_notifications(i8* %3, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %4
22: ; preds = %18, %12
%23 = phi i32 [ 108, %12 ], [ 118, %18 ]
%24 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), %18 ]
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%27 = call i32 @perror(i8* %24)
br label %28
28: ; preds = %16, %22
ret i32 -1
}