#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 EIO;
int ENOMEM;
int asprintf(char **, char *, char const *, double, double, double);
int /*<<< orphan*/ free(char *);
int write(int, char *, int);
int aprsis_login(int fd, const char *call, double lat, double lon,
                 double range) {
  char *buf;
  int ret, len;
  len = asprintf(
      &buf, "user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\r\n",
      call, lat, lon, range);
  if (len < 0)
    return -ENOMEM;
  ret = write(fd, buf, len);
  free(buf);
  if (ret != len)
    return -EIO;
  else
    return 0;
}


x86 assembly (clang, -O0):
<aprsis_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
lea    -0x30(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <asprintf@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jge    1191 <aprsis_login+0x61>
xor    %eax,%eax
mov    0x2e51(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <aprsis_login+0xa2>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
je     11cb <aprsis_login+0x9b>
xor    %eax,%eax
mov    0x2e1f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d2 <aprsis_login+0xa2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aprsis_login>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rdx
mov    %edi,%ebx
lea    0xec1(%rip),%rsi
mov    %rsp,%rdi
call   1050 <asprintf@plt>
test   %eax,%eax
js     1174 <aprsis_login+0x44>
mov    %eax,%ebp
mov    (%rsp),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmp    %ebp,%ebx
je     117f <aprsis_login+0x4f>
mov    0x2e6e(%rip),%rcx
jmp    117b <aprsis_login+0x4b>
mov    0x2e5d(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [60 x i8] c"user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\0D\0A\00"
@ENOMEM = global i32 0
@EIO = global i32 0
define i32 @aprsis_login(i32 %0, i8* %1, double %2, double %3, double %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
%15 = load i8*, i8** %8
%16 = load double, double* %9
%17 = load double, double* %10
%18 = load double, double* %11
%19 = call i32 @asprintf(i8** %12, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %15, double %16, double %17, double %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = load i32, i32* @ENOMEM
%24 = sub nsw i32 0, %23
store i32 %24, i32* %6
br label %39
25: ; preds = %5
%26 = load i32, i32* %7
%27 = load i8*, i8** %12
%28 = load i32, i32* %14
%29 = call i32 @write(i32 %26, i8* %27, i32 %28)
store i32 %29, i32* %13
%30 = load i8*, i8** %12
%31 = call i32 @free(i8* %30)
%32 = load i32, i32* %13
%33 = load i32, i32* %14
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = load i32, i32* @EIO
%37 = sub nsw i32 0, %36
store i32 %37, i32* %6
br label %39
38: ; preds = %25
store i32 0, i32* %6
br label %39
39: ; preds = %38, %35, %22
%40 = load i32, i32* %6
ret i32 %40
}

LLVM IR (-O2):
@.str = [60 x i8] c"user %s pass -1 vers Unknown 0.00 filter r/%.0f/%.0f/%.0f\0D\0A\00"
@ENOMEM = global i32 0
@EIO = global i32 0
define i32 @aprsis_login(i32 %0, i8* %1, double %2, double %3, double %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %1, double %2, double %3, double %4)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @ENOMEM
%12 = sub nsw i32 0, %11
br label %22
13: ; preds = %5
%14 = load i8*, i8** %6
%15 = call i32 @write(i32 %0, i8* %14, i32 %8)
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
%18 = icmp eq i32 %15, %8
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = load i32, i32* @EIO
%21 = sub nsw i32 0, %20
br label %22
22: ; preds = %13, %19, %10
%23 = phi i32 [ %12, %10 ], [ %21, %19 ], [ 0, %13 ]
ret i32 %23
}