#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 */
struct spwd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
scalar_t__ __sgetspent_r(char *, struct spwd *, char *, size_t);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int read(int, char *, size_t);
char *strchr(char *, char);
int __getspent_r(struct spwd *spwd, char *line_buff, size_t buflen,
                 int spwd_fd) {
  char *endptr;
  int line_len;
restart:
  if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
    return -1;
  endptr = strchr(line_buff, '\n');
  if (endptr != NULL)
    lseek(spwd_fd, (long)(1 + endptr - (line_buff + line_len)), SEEK_CUR);
  else {
    do {
      if ((line_len = read(spwd_fd, line_buff, buflen)) <= 0)
        return -1;
    } while (!(endptr = strchr(line_buff, '\n')));
    lseek(spwd_fd, (long)(endptr - line_buff) - line_len + 1, SEEK_CUR);
    goto restart;
  }
  if (__sgetspent_r(line_buff, spwd, line_buff, buflen) < 0)
    goto restart;
  return 0;
}


x86 assembly (clang, -O0):
<__getspent_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jg     117f <__getspent_r+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <__getspent_r+0x134>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11c8 <__getspent_r+0x88>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
add    %rcx,%rax
sub    %rax,%rsi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
jmp    1249 <__getspent_r+0x109>
jmp    11cd <__getspent_r+0x8d>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jg     11f5 <__getspent_r+0xb5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1274 <__getspent_r+0x134>
jmp    11fa <__getspent_r+0xba>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11cd <__getspent_r+0x8d>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
sub    %rax,%rsi
movslq -0x34(%rbp),%rax
sub    %rax,%rsi
add    $0x1,%rsi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
jmp    1157 <__getspent_r+0x17>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1030 <__sgetspent_r@plt>
cmp    $0x0,%rax
jge    126d <__getspent_r+0x12d>
jmp    1157 <__getspent_r+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__getspent_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %ecx,%edi
call   1060 <read@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
jle    1223 <__getspent_r+0xe3>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <__getspent_r+0x80>
mov    %ebp,%ecx
add    %rbx,%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    0x2e55(%rip),%rcx
mov    (%rcx),%edx
mov    %r13d,%edi
mov    %rax,%rsi
call   1050 <lseek@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <__sgetspent_r@plt>
test   %rax,%rax
js     1206 <__getspent_r+0xc6>
jmp    1220 <__getspent_r+0xe0>
nopl   0x0(%rax,%rax,1)
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <read@plt>
test   %eax,%eax
jle    1223 <__getspent_r+0xe3>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11c0 <__getspent_r+0x80>
mov    %ebp,%ecx
add    %rbx,%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    0x2def(%rip),%rcx
mov    (%rcx),%edx
mov    %r13d,%edi
mov    %rax,%rsi
call   1050 <lseek@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     116e <__getspent_r+0x2e>
jmp    1223 <__getspent_r+0xe3>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.spwd = type { i32 }
@SEEK_CUR = global i32 0
define i32 @__getspent_r(%struct.spwd* %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.spwd*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store %struct.spwd* %0, %struct.spwd** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
br label %12
12: ; preds = %71, %51, %4
%13 = load i32, i32* %9
%14 = load i8*, i8** %7
%15 = load i64, i64* %8
%16 = call i32 @read(i32 %13, i8* %14, i64 %15)
store i32 %16, i32* %11
%17 = icmp sle i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 -1, i32* %5
br label %73
19: ; preds = %12
%20 = load i8*, i8** %7
%21 = call i8* @strchr(i8* %20, i8 signext 10)
store i8* %21, i8** %10
%22 = load i8*, i8** %10
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %37
24: ; preds = %19
%25 = load i32, i32* %9
%26 = load i8*, i8** %10
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8*, i8** %7
%29 = load i32, i32* %11
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = ptrtoint i8* %27 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = load i32, i32* @SEEK_CUR
%36 = call i32 @lseek(i32 %25, i64 %34, i32 %35)
br label %64
37: ; preds = %19
br label %38
38: ; preds = %46, %37
%39 = load i32, i32* %9
%40 = load i8*, i8** %7
%41 = load i64, i64* %8
%42 = call i32 @read(i32 %39, i8* %40, i64 %41)
store i32 %42, i32* %11
%43 = icmp sle i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 -1, i32* %5
br label %73
45: ; preds = %38
br label %46
46: ; preds = %45
%47 = load i8*, i8** %7
%48 = call i8* @strchr(i8* %47, i8 signext 10)
store i8* %48, i8** %10
%49 = icmp ne i8* %48, null
%50 = xor i1 %49, true
br i1 %50, label %38, label %51
51: ; preds = %46
%52 = load i32, i32* %9
%53 = load i8*, i8** %10
%54 = load i8*, i8** %7
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = sub nsw i64 %57, %59
%61 = add nsw i64 %60, 1
%62 = load i32, i32* @SEEK_CUR
%63 = call i32 @lseek(i32 %52, i64 %61, i32 %62)
br label %12
64: ; preds = %24
%65 = load i8*, i8** %7
%66 = load %struct.spwd*, %struct.spwd** %6
%67 = load i8*, i8** %7
%68 = load i64, i64* %8
%69 = call i64 @__sgetspent_r(i8* %65, %struct.spwd* %66, i8* %67, i64 %68)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %64
br label %12
72: ; preds = %64
store i32 0, i32* %5
br label %73
73: ; preds = %72, %44, %18
%74 = load i32, i32* %5
ret i32 %74
}

LLVM IR (-O2):
%struct.spwd = type { i32 }
@SEEK_CUR = global i32 0
define i32 @__getspent_r(%struct.spwd* %0, i8* %1, i64 %2, i32 %3) {
%5 = tail call i32 @read(i32 %3, i8* %1, i64 %2)
%6 = icmp slt i32 %5, 1
br i1 %6, label %41, label %7
7: ; preds = %4
%8 = ptrtoint i8* %1 to i64
br label %9
9: ; preds = %7, %38
%10 = phi i32 [ %5, %7 ], [ %39, %38 ]
%11 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
%12 = icmp eq i8* %11, null
br i1 %12, label %24, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = zext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
%17 = ptrtoint i8* %14 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = load i32, i32* @SEEK_CUR
%21 = tail call i32 @lseek(i32 %3, i64 %19, i32 %20)
%22 = tail call i64 @__sgetspent_r(i8* %1, %struct.spwd* %0, i8* %1, i64 %2)
%23 = icmp slt i64 %22, 0
br i1 %23, label %38, label %41
24: ; preds = %9, %27
%25 = tail call i32 @read(i32 %3, i8* %1, i64 %2)
%26 = icmp slt i32 %25, 1
br i1 %26, label %41, label %27
27: ; preds = %24
%28 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 10)
%29 = icmp eq i8* %28, null
br i1 %29, label %24, label %30
30: ; preds = %27
%31 = ptrtoint i8* %28 to i64
%32 = zext i32 %25 to i64
%33 = add i64 %8, %32
%34 = sub i64 1, %33
%35 = add i64 %34, %31
%36 = load i32, i32* @SEEK_CUR
%37 = tail call i32 @lseek(i32 %3, i64 %35, i32 %36)
br label %38
38: ; preds = %30, %13
%39 = tail call i32 @read(i32 %3, i8* %1, i64 %2)
%40 = icmp slt i32 %39, 1
br i1 %40, label %41, label %9
41: ; preds = %38, %13, %24, %4
%42 = phi i32 [ -1, %4 ], [ -1, %24 ], [ -1, %38 ], [ 0, %13 ]
ret i32 %42
}