#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 */
struct sockaddr_storage {
  scalar_t__ ss_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
scalar_t__ AF_UNIX;
int /*<<< orphan*/ Log(int, char *);
int amp_asn_flag_done_direct(int);
int amp_asn_flag_done_local(int);
scalar_t__ getsockname(int, struct sockaddr *, int *);
int amp_asn_flag_done(int fd) {
  struct sockaddr_storage addr;
  socklen_t socklen;
  if (fd < 0) {
    Log(4, "Invalid file descriptor, not sending done flag");
    return -1;
  }
  socklen = sizeof(struct sockaddr_storage);
  if (getsockname(fd, (struct sockaddr *)&addr, &socklen) < 0) {
    return -1;
  }
  if (addr.ss_family == AF_UNIX) {
    return amp_asn_flag_done_local(fd);
  } else {
    return amp_asn_flag_done_direct(fd);
  }
}


x86 assembly (clang, -O0):
<amp_asn_flag_done>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1172 <amp_asn_flag_done+0x32>
mov    $0x4,%edi
lea    0xe9f(%rip),%rsi
call   1040 <Log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <amp_asn_flag_done+0x8e>
movl   $0x8,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <getsockname@plt>
cmp    $0x0,%rax
jge    119f <amp_asn_flag_done+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <amp_asn_flag_done+0x8e>
mov    -0x10(%rbp),%rax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <amp_asn_flag_done+0x83>
mov    -0x8(%rbp),%edi
call   1030 <amp_asn_flag_done_local@plt>
mov    %eax,-0x4(%rbp)
jmp    11ce <amp_asn_flag_done+0x8e>
mov    -0x8(%rbp),%edi
call   1060 <amp_asn_flag_done_direct@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<amp_asn_flag_done>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
js     1181 <amp_asn_flag_done+0x41>
mov    %edi,%ebx
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1050 <getsockname@plt>
test   %rax,%rax
js     1192 <amp_asn_flag_done+0x52>
mov    0x8(%rsp),%rax
mov    0x2e75(%rip),%rcx
cmp    (%rcx),%rax
jne    1199 <amp_asn_flag_done+0x59>
mov    %ebx,%edi
call   1030 <amp_asn_flag_done_local@plt>
jmp    11a0 <amp_asn_flag_done+0x60>
lea    0xe78(%rip),%rsi
mov    $0x4,%edi
call   1040 <Log@plt>
mov    $0xffffffff,%eax
jmp    11a0 <amp_asn_flag_done+0x60>
mov    %ebx,%edi
call   1060 <amp_asn_flag_done_direct@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [47 x i8] c"Invalid file descriptor, not sending done flag\00"
@AF_UNIX = global i64 0
define i32 @amp_asn_flag_done(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_storage
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @Log(i32 4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %27
10: ; preds = %1
store i32 8, i32* %5
%11 = load i32, i32* %3
%12 = bitcast %struct.sockaddr_storage* %4 to %struct.sockaddr*
%13 = call i64 @getsockname(i32 %11, %struct.sockaddr* %12, i32* %5)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 -1, i32* %2
br label %27
16: ; preds = %10
%17 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %4, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @AF_UNIX
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %3
%23 = call i32 @amp_asn_flag_done_local(i32 %22)
store i32 %23, i32* %2
br label %27
24: ; preds = %16
%25 = load i32, i32* %3
%26 = call i32 @amp_asn_flag_done_direct(i32 %25)
store i32 %26, i32* %2
br label %27
27: ; preds = %24, %21, %15, %8
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@.str = [47 x i8] c"Invalid file descriptor, not sending done flag\00"
@AF_UNIX = global i64 0
define i32 @amp_asn_flag_done(i32 %0) {
%2 = alloca %struct.sockaddr_storage
%3 = alloca i32
%4 = bitcast %struct.sockaddr_storage* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = icmp slt i32 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @Log(i32 4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %1
store i32 8, i32* %3
%10 = bitcast %struct.sockaddr_storage* %2 to %struct.sockaddr*
%11 = call i64 @getsockname(i32 %0, %struct.sockaddr* %10, i32* %3)
%12 = icmp slt i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %2, i64 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @AF_UNIX
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @amp_asn_flag_done_local(i32 %0)
br label %22
20: ; preds = %13
%21 = call i32 @amp_asn_flag_done_direct(i32 %0)
br label %22
22: ; preds = %9, %20, %18, %7
%23 = phi i32 [ -1, %7 ], [ %19, %18 ], [ %21, %20 ], [ -1, %9 ]
ret i32 %23
}