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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ die_errno(char *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memcmp(char *, char *, scalar_t__);
scalar_t__ strchr(char *, char);
scalar_t__ strlen(char *);
int has_binsh_line(FILE *file) {
  char item[sizeof("/bin/sh\n")];
  while (fgets(item, sizeof(item), file)) {
    int ch;
    if (!memcmp(item, "/bin/sh\n", strlen("/bin/sh\n") + 1))
      return 1;
    if (strchr(item, '\n'))
      continue;
    for (ch = 0; ch != '\n' && ch != EOF; ch = fgetc(file))
      ;
    if (ch == EOF)
      break;
  }
  if (ferror(file))
    die_errno("cannot read pipe");
  return 0;
}


x86 assembly (clang, -O0):
<has_binsh_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x9,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     125f <has_binsh_line+0xef>
lea    -0x19(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe59(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xe42(%rip),%rsi
call   1070 <memcmp@plt>
cmp    $0x0,%eax
jne    11d8 <has_binsh_line+0x68>
movl   $0x1,-0x4(%rbp)
jmp    1285 <has_binsh_line+0x115>
lea    -0x19(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     11f5 <has_binsh_line+0x85>
jmp    117c <has_binsh_line+0xc>
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x20(%rbp)
mov    %al,-0x29(%rbp)
je     121d <has_binsh_line+0xad>
mov    -0x20(%rbp),%eax
mov    0x2dd3(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    122d <has_binsh_line+0xbd>
jmp    1243 <has_binsh_line+0xd3>
jmp    1232 <has_binsh_line+0xc2>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x20(%rbp)
jmp    11fc <has_binsh_line+0x8c>
mov    -0x20(%rbp),%eax
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%eax
jne    125a <has_binsh_line+0xea>
jmp    125f <has_binsh_line+0xef>
jmp    117c <has_binsh_line+0xc>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     127e <has_binsh_line+0x10e>
lea    0xd90(%rip),%rdi
call   1090 <die_errno@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<has_binsh_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xf(%rsp),%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1207 <has_binsh_line+0xb7>
movabs $0xa68732f6e69622f,%r15
73 68 0a
lea    0xf(%rsp),%r14
mov    0x2e59(%rip),%r12
jmp    11b9 <has_binsh_line+0x69>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    %ecx,%eax
je     1207 <has_binsh_line+0xb7>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1207 <has_binsh_line+0xb7>
mov    0xf(%rsp),%rax
xor    %r15,%rax
movzbl 0x17(%rsp),%ecx
or     %rax,%rcx
je     1224 <has_binsh_line+0xd4>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    11a4 <has_binsh_line+0x54>
cmpl   $0x0,(%r12)
je     1207 <has_binsh_line+0xb7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    (%r12),%ecx
cmp    $0xa,%eax
je     11a0 <has_binsh_line+0x50>
cmp    %ecx,%eax
jne    11f0 <has_binsh_line+0xa0>
jmp    11a0 <has_binsh_line+0x50>
mov    %rbx,%rdi
call   1030 <ferror@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1229 <has_binsh_line+0xd9>
lea    0xdec(%rip),%rdi
call   1070 <die_errno@plt>
jmp    1229 <has_binsh_line+0xd9>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/bin/sh\0A\00"
@EOF = global i32 0
@.str.1 = [17 x i8] c"cannot read pipe\00"
define i32 @has_binsh_line(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [9 x i8]
%5 = alloca i32
store i32* %0, i32** %3
br label %6
6: ; preds = %42, %22, %1
%7 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%8 = load i32*, i32** %3
%9 = call i64 @fgets(i8* %7, i32 9, i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %43
11: ; preds = %6
%12 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%13 = call i64 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = add nsw i64 %13, 1
%15 = call i32 @memcmp(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %11
store i32 1, i32* %2
br label %50
18: ; preds = %11
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%20 = call i64 @strchr(i8* %19, i8 signext 10)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
br label %6
23: ; preds = %18
store i32 0, i32* %5
br label %24
24: ; preds = %34, %23
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = load i32, i32* %5
%29 = load i32, i32* @EOF
%30 = icmp ne i32 %28, %29
br label %31
31: ; preds = %27, %24
%32 = phi i1 [ false, %24 ], [ %30, %27 ]
br i1 %32, label %33, label %37
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i32*, i32** %3
%36 = call i32 @fgetc(i32* %35)
store i32 %36, i32* %5
br label %24
37: ; preds = %31
%38 = load i32, i32* %5
%39 = load i32, i32* @EOF
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %43
42: ; preds = %37
br label %6
43: ; preds = %41, %6
%44 = load i32*, i32** %3
%45 = call i64 @ferror(i32* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @die_errno(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
store i32 0, i32* %2
br label %50
50: ; preds = %49, %17
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [9 x i8] c"/bin/sh\0A\00"
@EOF = global i32 0
@.str.1 = [17 x i8] c"cannot read pipe\00"
define i32 @has_binsh_line(i32* nocapture %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = call i64 @fgets(i8* %3, i32 9, i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %1, %23
%7 = call i32 @bcmp(i8* dereferenceable(9) %3, i8* dereferenceable(9) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 9)
%8 = icmp eq i32 %7, 0
br i1 %8, label %31, label %9
9: ; preds = %6
%10 = call i64 @strchr(i8* %3, i8 signext 10)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %13, 0
br i1 %14, label %26, label %15
15: ; preds = %12, %15
%16 = call i32 @fgetc(i32* %0)
%17 = icmp ne i32 %16, 10
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %16, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %15, label %21
21: ; preds = %15
%22 = icmp eq i32 %16, %18
br i1 %22, label %26, label %23
23: ; preds = %21, %9
%24 = call i64 @fgets(i8* %3, i32 9, i32* %0)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %6
26: ; preds = %12, %23, %21, %1
%27 = call i64 @ferror(i32* %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @die_errno(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %6, %26, %29
%32 = phi i32 [ 0, %29 ], [ 0, %26 ], [ 1, %6 ]
ret i32 %32
}