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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int scan_hldate(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
char *strpbrk(char *, char *);
char *fgetline1(char *lbuff, int lsize, FILE *fp) {
  char *dp;
  char *ep;
  time_t udate;
  char lb[2048];
  char sd[2048];
  if (fgets(lb, 2048, fp) == NULL)
    return NULL;
  if (dp = strpbrk(lb, "\r\n"))
    *dp = 0;
  if ((dp = strchr(lb, '[')) && (ep = strchr(dp + 1, ']'))) {
    udate = scan_hldate(dp + 1, sd);
    if (ep[1] == ' ')
      ep++;
    strcpy(dp, ep + 1);
    snprintf(lbuff, lsize, "%d %s %s", udate, sd, lb);
  } else {
    snprintf(lbuff, lsize, "0 - %s", lb);
  }
  return lbuff;
}


x86 assembly (clang, -O0):
<fgetline1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x840(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11a2 <fgetline1+0x42>
movq   $0x0,-0x8(%rbp)
jmp    129d <fgetline1+0x13d>
lea    -0x840(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1070 <strpbrk@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11ca <fgetline1+0x6a>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x840(%rbp),%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1279 <fgetline1+0x119>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1279 <fgetline1+0x119>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
lea    -0x1040(%rbp),%rsi
call   1080 <scan_hldate@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x20,%eax
jne    123d <fgetline1+0xdd>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
add    $0x1,%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x34(%rbp),%ecx
lea    -0x1040(%rbp),%r8
lea    -0x840(%rbp),%r9
lea    0xd96(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    1295 <fgetline1+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x840(%rbp),%rcx
lea    0xd7e(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetline1>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%rdi
mov    $0x800,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     121f <fgetline1+0xbf>
lea    0xe6c(%rip),%rsi
mov    %rsp,%rdi
call   1070 <strpbrk@plt>
test   %rax,%rax
je     11a4 <fgetline1+0x44>
movb   $0x0,(%rax)
mov    %rsp,%rdi
mov    $0x5b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1224 <fgetline1+0xc4>
mov    %rax,%rbp
lea    0x1(%rax),%r12
mov    %r12,%rdi
mov    $0x5d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1224 <fgetline1+0xc4>
mov    %rax,%rbx
lea    0x800(%rsp),%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <scan_hldate@plt>
mov    %eax,%r12d
cmpb   $0x20,0x1(%rbx)
lea    0x1(%rbx),%rsi
cmovne %rbx,%rsi
add    $0x1,%rsi
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xdfc(%rip),%rdx
mov    %rsp,%r9
mov    %r15,%rdi
mov    %r14d,%esi
mov    %r12d,%ecx
mov    %r13,%r8
xor    %eax,%eax
call   1050 <snprintf@plt>
jmp    123b <fgetline1+0xdb>
xor    %r15d,%r15d
jmp    123b <fgetline1+0xdb>
lea    0xde1(%rip),%rdx
mov    %rsp,%rcx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %r15,%rax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [9 x i8] c"%d %s %s\00"
@.str.2 = [7 x i8] c"0 - %s\00"
define i8* @fgetline1(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [2048 x i8]
%12 = alloca [2048 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%14 = load i32*, i32** %7
%15 = call i32* @fgets(i8* %13, i32 2048, i32* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %3
store i8* null, i8** %4
br label %64
18: ; preds = %3
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%20 = call i8* @strpbrk(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load i8*, i8** %8
store i8 0, i8* %23
br label %24
24: ; preds = %22, %18
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%26 = call i8* @strchr(i8* %25, i8 signext 91)
store i8* %26, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %57
28: ; preds = %24
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = call i8* @strchr(i8* %30, i8 signext 93)
store i8* %31, i8** %9
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %57
33: ; preds = %28
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%37 = call i32 @scan_hldate(i8* %35, i8* %36)
store i32 %37, i32* %10
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 32
br i1 %42, label %43, label %46
43: ; preds = %33
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %9
br label %46
46: ; preds = %43, %33
%47 = load i8*, i8** %8
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = call i32 @strcpy(i8* %47, i8* %49)
%51 = load i8*, i8** %5
%52 = load i32, i32* %6
%53 = load i32, i32* %10
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* %12, i64 0, i64 0
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%56 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %51, i32 %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %53, i8* %54, i8* %55)
br label %62
57: ; preds = %28, %24
%58 = load i8*, i8** %5
%59 = load i32, i32* %6
%60 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%61 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %58, i32 %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %60)
br label %62
62: ; preds = %57, %46
%63 = load i8*, i8** %5
store i8* %63, i8** %4
br label %64
64: ; preds = %62, %17
%65 = load i8*, i8** %4
ret i8* %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [9 x i8] c"%d %s %s\00"
@.str.2 = [7 x i8] c"0 - %s\00"
define i8* @fgetline1(i8* %0, i32 %1, i32* nocapture %2) {
%4 = alloca [2048 x i8]
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%8 = call i32* @fgets(i8* %6, i32 2048, i32* %2)
%9 = icmp eq i32* %8, null
br i1 %9, label %32, label %10
10: ; preds = %3
%11 = call i8* @strpbrk(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 0, i8* %11
br label %14
14: ; preds = %13, %10
%15 = call i8* @strchr(i8* %6, i8 signext 91)
%16 = icmp eq i8* %15, null
br i1 %16, label %30, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %15, i64 1
%19 = call i8* @strchr(i8* %18, i8 signext 93)
%20 = icmp eq i8* %19, null
br i1 %20, label %30, label %21
21: ; preds = %17
%22 = call i32 @scan_hldate(i8* %18, i8* %7)
%23 = getelementptr inbounds i8, i8* %19, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 32
%26 = select i1 %25, i8* %23, i8* %19
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = call i32 @strcpy(i8* %15, i8* %27)
%29 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %7, i8* %6)
br label %32
30: ; preds = %17, %14
%31 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %32
32: ; preds = %21, %30, %3
%33 = phi i8* [ null, %3 ], [ %0, %30 ], [ %0, %21 ]
ret i8* %33
}