#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 */

/* Variables and functions */
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ writeline(int, char *);
int check_prompt(int s, char *buff, char *passwd) {
  if (!strcmp(buff, "> ")) {
    return (1);
  }
  if (!strcmp(buff, "password: \x1b]E") && passwd) {
    writeline(s, passwd);
    writeline(s, "\r\n");
    return (2);
  }
  return (0);
}


x86 assembly (clang, -O0):
<check_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1158 <check_prompt+0x38>
movl   $0x1,-0x4(%rbp)
jmp    11aa <check_prompt+0x8a>
mov    -0x10(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11a3 <check_prompt+0x83>
cmpq   $0x0,-0x18(%rbp)
je     11a3 <check_prompt+0x83>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <writeline@plt>
mov    -0x8(%rbp),%edi
lea    0xe7f(%rip),%rsi
call   1040 <writeline@plt>
movl   $0x2,-0x4(%rbp)
jmp    11aa <check_prompt+0x8a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_prompt>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %edi,%r14d
lea    0xecc(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     117d <check_prompt+0x5d>
lea    0xebc(%rip),%rsi
mov    %rbp,%rdi
call   1030 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %rbx,%rbx
je     1182 <check_prompt+0x62>
test   %ecx,%ecx
jne    1182 <check_prompt+0x62>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <writeline@plt>
lea    0xea3(%rip),%rsi
mov    %r14d,%edi
call   1040 <writeline@plt>
mov    $0x2,%eax
jmp    1182 <check_prompt+0x62>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"> \00"
@.str.1 = [14 x i8] c"password: \1B]E\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @check_prompt(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%8 = load i8*, i8** %6
%9 = call i32 @strcmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %3
store i32 1, i32* %4
br label %26
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* %5
%21 = load i8*, i8** %7
%22 = call i32 @writeline(i32 %20, i8* %21)
%23 = load i32, i32* %5
%24 = call i32 @writeline(i32 %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %4
br label %26
25: ; preds = %16, %12
store i32 0, i32* %4
br label %26
26: ; preds = %25, %19, %11
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [3 x i8] c"> \00"
@.str.1 = [14 x i8] c"password: \1B]E\00"
@.str.2 = [3 x i8] c"\0D\0A\00"
define i32 @check_prompt(i32 %0, i8* nocapture %1, i8* %2) {
%4 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
%9 = icmp ne i8* %2, null
%10 = and i1 %9, %8
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = tail call i32 @writeline(i32 %0, i8* %2)
%13 = tail call i32 @writeline(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %6, %3, %11
%15 = phi i32 [ 2, %11 ], [ 1, %3 ], [ 0, %6 ]
ret i32 %15
}