#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*/ printf(char *, unsigned char *);
int /*<<< orphan*/ read(int, unsigned char *, int);
scalar_t__ strncasecmp(unsigned char *, char *, int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int programmer_proto_check(int port) {
  unsigned char command;
  unsigned char receive[5] = "XYZA\0";
  command = 21;
  write(port, &command, 1);
  read(port, receive, 4);
  if (strncasecmp(receive, "P018", 4) != 0) {
    printf("Version: %4s\n", receive);
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<programmer_proto_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0xeaf(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xeaa(%rip),%al
mov    %al,-0xa(%rbp)
movb   $0x15,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0xe(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
lea    -0xe(%rbp),%rdi
lea    0xe77(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
je     11be <programmer_proto_check+0x7e>
lea    -0xe(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11c5 <programmer_proto_check+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<programmer_proto_check>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movb   $0x0,0x14(%rsp)
movl   $0x415a5958,0x10(%rsp)
41
movb   $0x15,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1050 <read@plt>
lea    0xe80(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
je     11af <programmer_proto_check+0x6f>
lea    0xe6c(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
mov    $0xfffffffe,%eax
jmp    11b1 <programmer_proto_check+0x71>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.programmer_proto_check.receive = [5 x i8] c"XYZA\00"
@.str = [5 x i8] c"P018\00"
@.str.1 = [14 x i8] c"Version: %4s\0A\00"
define i32 @programmer_proto_check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca [5 x i8]
store i32 %0, i32* %3
%6 = bitcast [5 x i8]* %5 to i8*
store i8 21, i8* %4
%7 = load i32, i32* %3
%8 = call i32 @write(i32 %7, i8* %4, i32 1)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 4)
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%13 = call i64 @strncasecmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 -2, i32* %2
br label %19
18: ; preds = %1
store i32 0, i32* %2
br label %19
19: ; preds = %18, %15
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@__const.programmer_proto_check.receive = [5 x i8] c"XYZA\00"
@.str = [5 x i8] c"P018\00"
@.str.1 = [14 x i8] c"Version: %4s\0A\00"
define i32 @programmer_proto_check(i32 %0) {
%2 = alloca i8
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
store i8 21, i8* %2
%5 = call i32 @write(i32 %0, i8* %2, i32 1)
%6 = call i32 @read(i32 %0, i8* %4, i32 4)
%7 = call i64 @strncasecmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ -2, %9 ], [ 0, %1 ]
ret i32 %12
}