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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *realloc(char *, int);
int strlen(char *);
int dinfo_read_dasd_uid(char *uidfile, char *readbuf, int readbuflen) {
  FILE *dasduid;
  int offset = 0;
  if ((dasduid = fopen(uidfile, "r")) == NULL)
    return -1;
  while (fgets(readbuf + offset, 80, dasduid) &&
         readbuf[strlen(readbuf) - 1] != '\n') {
    offset += 80 - 1;
    if (offset + 80 - 1 >= readbuflen) {
      readbuf = realloc(readbuf, readbuflen + 80 - 1);
      readbuflen += 80 - 1;
    }
  }
  fclose(dasduid);
  if (strlen(readbuf) <= 1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<dinfo_read_dasd_uid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1194 <dinfo_read_dasd_uid+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <dinfo_read_dasd_uid+0x11b>
jmp    1199 <dinfo_read_dasd_uid+0x49>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x2d(%rbp)
je     11ee <dinfo_read_dasd_uid+0x9e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11fe <dinfo_read_dasd_uid+0xae>
jmp    123d <dinfo_read_dasd_uid+0xed>
mov    -0x2c(%rbp),%eax
add    $0x4f,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x50,%eax
sub    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jl     1238 <dinfo_read_dasd_uid+0xe8>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    $0x50,%esi
sub    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x4f,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <dinfo_read_dasd_uid+0x49>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jg     1264 <dinfo_read_dasd_uid+0x114>
movl   $0xffffffff,-0x4(%rbp)
jmp    126b <dinfo_read_dasd_uid+0x11b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dinfo_read_dasd_uid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
lea    0xe9c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1205 <dinfo_read_dasd_uid+0xb5>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e7 <dinfo_read_dasd_uid+0x97>
mov    $0x4f,%ebp
jmp    11ba <dinfo_read_dasd_uid+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rdi
mov    $0x50,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
add    $0x4f,%rbp
test   %rax,%rax
je     11e7 <dinfo_read_dasd_uid+0x97>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
je     11e7 <dinfo_read_dasd_uid+0x97>
lea    0x4f(%rbp),%eax
cmp    %r15d,%eax
jl     11a0 <dinfo_read_dasd_uid+0x50>
add    $0x4f,%r15d
mov    %rbx,%rdi
mov    %r15d,%esi
call   1060 <realloc@plt>
mov    %rax,%rbx
jmp    11a0 <dinfo_read_dasd_uid+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
setl   %al
neg    %eax
jmp    120a <dinfo_read_dasd_uid+0xba>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @dinfo_read_dasd_uid(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %60
14: ; preds = %3
br label %15
15: ; preds = %51, %14
%16 = load i8*, i8** %6
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i32*, i32** %8
%21 = call i64 @fgets(i8* %19, i32 80, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = load i8*, i8** %6
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br label %33
33: ; preds = %23, %15
%34 = phi i1 [ false, %15 ], [ %32, %23 ]
br i1 %34, label %35, label %52
35: ; preds = %33
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 79
store i32 %37, i32* %9
%38 = load i32, i32* %9
%39 = add nsw i32 %38, 80
%40 = sub nsw i32 %39, 1
%41 = load i32, i32* %7
%42 = icmp sge i32 %40, %41
br i1 %42, label %43, label %51
43: ; preds = %35
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 80
%47 = sub nsw i32 %46, 1
%48 = call i8* @realloc(i8* %44, i32 %47)
store i8* %48, i8** %6
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 79
store i32 %50, i32* %7
br label %51
51: ; preds = %43, %35
br label %15
52: ; preds = %33
%53 = load i32*, i32** %8
%54 = call i32 @fclose(i32* %53)
%55 = load i8*, i8** %6
%56 = call i32 @strlen(i8* %55)
%57 = icmp sle i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %52
store i32 -1, i32* %4
br label %60
59: ; preds = %52
store i32 0, i32* %4
br label %60
60: ; preds = %59, %58, %13
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @dinfo_read_dasd_uid(i8* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %39, label %6
6: ; preds = %3
%7 = tail call i64 @fgets(i8* %1, i32 80, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %33, label %9
9: ; preds = %6, %27
%10 = phi i64 [ %20, %27 ], [ 0, %6 ]
%11 = phi i32 [ %29, %27 ], [ %2, %6 ]
%12 = phi i8* [ %28, %27 ], [ %1, %6 ]
%13 = tail call i32 @strlen(i8* %12)
%14 = add nsw i32 %13, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %33, label %19
19: ; preds = %9
%20 = add nuw i64 %10, 79
%21 = trunc i64 %10 to i32
%22 = add i32 %21, 158
%23 = icmp slt i32 %22, %11
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = add nsw i32 %11, 79
%26 = tail call i8* @realloc(i8* %12, i32 %25)
br label %27
27: ; preds = %24, %19
%28 = phi i8* [ %26, %24 ], [ %12, %19 ]
%29 = phi i32 [ %25, %24 ], [ %11, %19 ]
%30 = getelementptr inbounds i8, i8* %28, i64 %20
%31 = tail call i64 @fgets(i8* %30, i32 80, i32* %4)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %9
33: ; preds = %9, %27, %6
%34 = phi i8* [ %1, %6 ], [ %28, %27 ], [ %12, %9 ]
%35 = tail call i32 @fclose(i32* %4)
%36 = tail call i32 @strlen(i8* %34)
%37 = icmp slt i32 %36, 2
%38 = sext i1 %37 to i32
br label %39
39: ; preds = %33, %3
%40 = phi i32 [ -1, %3 ], [ %38, %33 ]
ret i32 %40
}