#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*/ CloseAdrPort();
scalar_t__ WriteAdrPort(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int close_gatectl() {
  char sCmd[254];
  int iSpot;
  strcpy(sCmd, "$KE,WRA,000000000000000000000000");
  iSpot = strlen(sCmd);
  sCmd[iSpot] = 0x0d;
  sCmd[iSpot + 1] = 0x0a;
  sCmd[iSpot + 2] = 0x00;
  if (WriteAdrPort(sCmd) < 0) {
    return -1;
  }
  CloseAdrPort();
  return 0;
}


x86 assembly (clang, -O0):
<close_gatectl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x114(%rbp)
movslq -0x114(%rbp),%rax
movb   $0xd,-0x110(%rbp,%rax,1)
0d
mov    -0x114(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0xa,-0x110(%rbp,%rax,1)
0a
mov    -0x114(%rbp),%eax
add    $0x2,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1030 <WriteAdrPort@plt>
cmp    $0x0,%rax
jge    11c7 <close_gatectl+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <close_gatectl+0x95>
mov    $0x0,%al
call   1050 <CloseAdrPort@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_gatectl>:
push   %rbx
sub    $0x100,%rsp
lea    0xeb1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movw   $0xa0d,(%rsp,%rax,1)
movb   $0x0,0x2(%rsp,%rax,1)
mov    %rbx,%rdi
call   1030 <WriteAdrPort@plt>
test   %rax,%rax
js     1187 <close_gatectl+0x47>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <CloseAdrPort@plt>
jmp    118c <close_gatectl+0x4c>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"$KE,WRA,000000000000000000000000\00"
define i32 @close_gatectl() {
%1 = alloca i32
%2 = alloca [254 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 %9
store i8 13, i8* %10
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 %13
store i8 10, i8* %14
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [254 x i8], [254 x i8]* %2, i64 0, i64 0
%20 = call i64 @WriteAdrPort(i8* %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %0
store i32 -1, i32* %1
br label %25
23: ; preds = %0
%24 = call i32 (...) @CloseAdrPort()
store i32 0, i32* %1
br label %25
25: ; preds = %23, %22
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [33 x i8] c"$KE,WRA,000000000000000000000000\00"
define i32 @close_gatectl() {
%1 = alloca [254 x i8]
%2 = getelementptr inbounds [254 x i8], [254 x i8]* %1, i64 0, i64 0
%3 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strlen(i8* %2)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [254 x i8], [254 x i8]* %1, i64 0, i64 %5
store i8 13, i8* %6
%7 = add nsw i32 %4, 1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [254 x i8], [254 x i8]* %1, i64 0, i64 %8
store i8 10, i8* %9
%10 = add nsw i32 %4, 2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [254 x i8], [254 x i8]* %1, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i64 @WriteAdrPort(i8* %2)
%14 = icmp slt i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 (...) @CloseAdrPort()
br label %17
17: ; preds = %0, %15
%18 = phi i32 [ 0, %15 ], [ -1, %0 ]
ret i32 %18
}