#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ getline(char **const, size_t *const, int /*<<< orphan*/ *const);
ssize_t our_getline(char **const lineptr, size_t *const n, FILE *const stream) {
  do {
    const ssize_t ret = getline(lineptr, n, stream);
    if (ret >= 0) {
      return ret;
    }
  } while (errno == EINTR);
  return 0;
}


x86 assembly (clang, -O0):
<our_getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <getline@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jl     1151 <our_getline+0x41>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <our_getline+0x68>
jmp    1156 <our_getline+0x46>
mov    0x2e83(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
je     1124 <our_getline+0x14>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<our_getline>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    0x2eb7(%rip),%r12
mov    0x2ea8(%rip),%r13
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <getline@plt>
test   %rax,%rax
jns    114f <our_getline+0x3f>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1130 <our_getline+0x20>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define i64 @our_getline(i8** %0, i64* %1, i32* %2) {
%4 = alloca i64
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca i32*
%8 = alloca i64
store i8** %0, i8*** %5
store i64* %1, i64** %6
store i32* %2, i32** %7
br label %9
9: ; preds = %19, %3
%10 = load i8**, i8*** %5
%11 = load i64*, i64** %6
%12 = load i32*, i32** %7
%13 = call i64 @getline(i8** %10, i64* %11, i32* %12)
store i64 %13, i64* %8
%14 = load i64, i64* %8
%15 = icmp sge i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = load i64, i64* %8
store i64 %17, i64* %4
br label %24
18: ; preds = %9
br label %19
19: ; preds = %18
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %9, label %23
23: ; preds = %19
store i64 0, i64* %4
br label %24
24: ; preds = %23, %16
%25 = load i64, i64* %4
ret i64 %25
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define i64 @our_getline(i8** %0, i64* %1, i32* %2) {
br label %4
4: ; preds = %7, %3
%5 = tail call i64 @getline(i8** %0, i64* %1, i32* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %8, %9
br i1 %10, label %4, label %11
11: ; preds = %4, %7
%12 = phi i64 [ %5, %4 ], [ 0, %7 ]
ret i64 %12
}