#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, unsigned long *id, unsigned long *extra) {
  int i;
  unsigned char c;
  unsigned char *response = (unsigned char *)"\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    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    0xec9(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
cmp    $0x5,%eax
je     1167 <stinger_init+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <stinger_init+0xb1>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11ca <stinger_init+0xaa>
mov    -0x8(%rbp),%edi
lea    -0x1d(%rbp),%rsi
mov    $0xc8,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    11ab <stinger_init+0x8b>
movzbl -0x1d(%rbp),%eax
mov    -0x28(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11b7 <stinger_init+0x97>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d1 <stinger_init+0xb1>
jmp    11bc <stinger_init+0x9c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116e <stinger_init+0x4e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%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, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8*
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %10
%11 = load i32, i32* %5
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%13 = icmp ne i32 %12, 5
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 -1, i32* %4
br label %39
15: ; preds = %3
store i32 0, i32* %8
br label %16
16: ; preds = %35, %15
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 16
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = load i32, i32* %5
%21 = call i64 @readchar(i32 %20, i8* %9, i32 200)
%22 = icmp ne i64 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %19
%24 = load i8, i8* %9
%25 = zext i8 %24 to i32
%26 = load i8*, i8** %10
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp ne i32 %25, %31
br i1 %32, label %33, label %34
33: ; preds = %23, %19
store i32 -1, i32* %4
br label %39
34: ; preds = %23
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %16
38: ; preds = %16
store i32 0, i32* %4
br label %39
39: ; preds = %38, %33, %14
%40 = load i32, i32* %4
ret i32 %40
}

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, i64* nocapture readnone %1, i64* nocapture readnone %2) {
%4 = alloca i8
%5 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%6 = icmp eq i32 %5, 5
br i1 %6, label %10, label %19
7: ; preds = %14
%8 = add nuw nsw i64 %11, 1
%9 = icmp eq i64 %8, 16
br i1 %9, label %19, label %10
10: ; preds = %3, %7
%11 = phi i64 [ %8, %7 ], [ 0, %3 ]
%12 = call i64 @readchar(i32 %0, i8* %4, i32 200)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8, i8* %4
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %11
%17 = load i8, i8* %16
%18 = icmp eq i8 %15, %17
br i1 %18, label %7, label %19
19: ; preds = %7, %10, %14, %3
%20 = phi i32 [ -1, %3 ], [ 0, %7 ], [ -1, %10 ], [ -1, %14 ]
ret i32 %20
}