#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*/ GenClose(void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ findstr(char *, char *);
char *grab_string(void *theEnv, FILE *fp, char *buf, int bufsize) {
  if (fgets(buf, bufsize, fp) == NULL) {
    GenClose(theEnv, fp);
    return (NULL);
  }
  if ((buf[0] == ('$')) && (buf[1] == ('$'))) {
    buf[0] = (' ');
    buf[1] = (' ');
  } else if (findstr(buf, "END-ENTRY") >= 0) {
    buf = NULL;
    GenClose(theEnv, fp);
  }
  return (buf);
}


x86 assembly (clang, -O0):
<grab_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <fgets@plt>
cmp    $0x0,%rax
jne    117b <grab_string+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <GenClose@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ec <grab_string+0xbc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11b0 <grab_string+0x80>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x24,%eax
jne    11b0 <grab_string+0x80>
mov    -0x20(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x20,0x1(%rax)
jmp    11e4 <grab_string+0xb4>
mov    -0x20(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1040 <findstr@plt>
cmp    $0x0,%rax
jl     11df <grab_string+0xaf>
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <GenClose@plt>
jmp    11e4 <grab_string+0xb4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grab_string>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
mov    %ecx,%esi
mov    %r14,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     1176 <grab_string+0x46>
cmpb   $0x24,(%rbx)
jne    1162 <grab_string+0x32>
cmpb   $0x24,0x1(%rbx)
jne    1162 <grab_string+0x32>
movw   $0x2020,(%rbx)
jmp    1183 <grab_string+0x53>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1040 <findstr@plt>
test   %rax,%rax
js     1183 <grab_string+0x53>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <GenClose@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"END-ENTRY\00"
define i8* @grab_string(i8* %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%10 = load i8*, i8** %8
%11 = load i32, i32* %9
%12 = load i32*, i32** %7
%13 = call i32* @fgets(i8* %10, i32 %11, i32* %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = load i32*, i32** %7
%18 = call i32 @GenClose(i8* %16, i32* %17)
store i8* null, i8** %5
br label %47
19: ; preds = %4
%20 = load i8*, i8** %8
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 36
br i1 %24, label %25, label %36
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 36
br i1 %30, label %31, label %36
31: ; preds = %25
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 32, i8* %33
%34 = load i8*, i8** %8
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8 32, i8* %35
br label %45
36: ; preds = %25, %19
%37 = load i8*, i8** %8
%38 = call i64 @findstr(i8* %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%39 = icmp sge i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
store i8* null, i8** %8
%41 = load i8*, i8** %6
%42 = load i32*, i32** %7
%43 = call i32 @GenClose(i8* %41, i32* %42)
br label %44
44: ; preds = %40, %36
br label %45
45: ; preds = %44, %31
%46 = load i8*, i8** %8
store i8* %46, i8** %5
br label %47
47: ; preds = %45, %15
%48 = load i8*, i8** %5
ret i8* %48
}

LLVM IR (-O2):
@.str = [10 x i8] c"END-ENTRY\00"
define i8* @grab_string(i8* %0, i32* %1, i8* %2, i32 %3) {
%5 = tail call i32* @fgets(i8* %2, i32 %3, i32* %1)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @GenClose(i8* %0, i32* %1)
br label %22
9: ; preds = %4
%10 = load i8, i8* %2
%11 = icmp eq i8 %10, 36
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %2, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 36
br i1 %15, label %16, label %17
16: ; preds = %12
store i8 32, i8* %2
store i8 32, i8* %13
br label %22
17: ; preds = %12, %9
%18 = tail call i64 @findstr(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = icmp sgt i64 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @GenClose(i8* %0, i32* %1)
br label %22
22: ; preds = %16, %20, %17, %7
%23 = phi i8* [ null, %7 ], [ %2, %16 ], [ null, %20 ], [ %2, %17 ]
ret i8* %23
}