#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 */
scalar_t__ readchar(int, unsigned char *, int);
int write(int, char *, int);
int stinger_init(int fd) {
  int i;
  unsigned char c;
  unsigned char *response = "\r\n0600520058C272";
  if (write(fd, " E5E5", 5) != 5)
    return -1;
  for (i = 0; i < 16; i++)
    if (readchar(fd, &c, 200) || (c != response[i]))
      return -1;
  return 0;
}


x86 assembly (clang, -O0):
<stinger_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    0xed1(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
je     115f <stinger_init+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <stinger_init+0xa9>
movl   $0x0,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    11c2 <stinger_init+0xa2>
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0xc8,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    11a3 <stinger_init+0x83>
movzbl -0xd(%rbp),%eax
mov    -0x18(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11af <stinger_init+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c9 <stinger_init+0xa9>
jmp    11b4 <stinger_init+0x94>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1166 <stinger_init+0x46>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stinger_init>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xedc(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    $0xffffffff,%r14d
cmp    $0x5,%eax
jne    118c <stinger_init+0x6c>
xor    %ebx,%ebx
lea    0xf(%rsp),%r15
lea    0xea8(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc8,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    118c <stinger_init+0x6c>
movzbl 0xf(%rsp),%eax
cmp    (%rbx,%r12,1),%al
jne    118c <stinger_init+0x6c>
add    $0x1,%rbx
cmp    $0x10,%rbx
jne    1160 <stinger_init+0x40>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"\0D\0A0600520058C272\00"
@.str.1 = [6 x i8] c" E5E5\00"
define i32 @stinger_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
store i32 %0, i32* %3
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = load i32, i32* %3
%8 = call i32 @write(i32 %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%9 = icmp ne i32 %8, 5
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %35
11: ; preds = %1
store i32 0, i32* %4
br label %12
12: ; preds = %31, %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %34
15: ; preds = %12
%16 = load i32, i32* %3
%17 = call i64 @readchar(i32 %16, i8* %5, i32 200)
%18 = icmp ne i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = load i8, i8* %5
%21 = zext i8 %20 to i32
%22 = load i8*, i8** %6
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp ne i32 %21, %27
br i1 %28, label %29, label %30
29: ; preds = %19, %15
store i32 -1, i32* %2
br label %35
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %12
34: ; preds = %12
store i32 0, i32* %2
br label %35
35: ; preds = %34, %29, %10
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [17 x i8] c"\0D\0A0600520058C272\00"
@.str.1 = [6 x i8] c" E5E5\00"
define i32 @stinger_init(i32 %0) {
%2 = alloca i8
%3 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%4 = icmp eq i32 %3, 5
br i1 %4, label %8, label %17
5: ; preds = %12
%6 = add nuw nsw i64 %9, 1
%7 = icmp eq i64 %6, 16
br i1 %7, label %17, label %8
8: ; preds = %1, %5
%9 = phi i64 [ %6, %5 ], [ 0, %1 ]
%10 = call i64 @readchar(i32 %0, i8* %2, i32 200)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8, i8* %2
%14 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %9
%15 = load i8, i8* %14
%16 = icmp eq i8 %13, %15
br i1 %16, label %5, label %17
17: ; preds = %5, %8, %12, %1
%18 = phi i32 [ -1, %1 ], [ 0, %5 ], [ -1, %8 ], [ -1, %12 ]
ret i32 %18
}