#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_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ logmsg;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ logging(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int Accept(int sockfd, struct sockaddr_in sockaddr, int sin_size) {
  int client_fd;
  if ((client_fd = accept(sockfd, (struct sockaddr *)&sockaddr, &sin_size)) <
      0) {
    perror("accept");
    return -1;
  }
  char logmsg[128];
  snprintf(logmsg, sizeof(logmsg), "New incoming connection - %d\n", client_fd);
  logging("lsrp-router.log", logmsg);
  return client_fd;
}


x86 assembly (clang, -O0):
<Accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %esi,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1188 <Accept+0x48>
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bc <Accept+0x7c>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x80,%esi
lea    0xe69(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0xa0(%rbp),%rsi
lea    0xe74(%rip),%rdi
call   1040 <logging@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Accept>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %esi,0x8(%rsp)
mov    %edx,0xc(%rsp)
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1060 <accept@plt>
test   %eax,%eax
js     119e <Accept+0x5e>
mov    %eax,%ebx
lea    0xe99(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x80,%esi
mov    %eax,%ecx
call   1030 <snprintf@plt>
lea    0xe9c(%rip),%rdi
mov    %r14,%rsi
call   1040 <logging@plt>
mov    %ebx,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1191 <Accept+0x51>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@.str.1 = [30 x i8] c"New incoming connection - %d\0A\00"
@.str.2 = [16 x i8] c"lsrp-router.log\00"
define i32 @Accept(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %1, i32* %10
store i32 %0, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %6
%12 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%13 = call i32 @accept(i32 %11, %struct.sockaddr* %12, i32* %7)
store i32 %13, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %24
17: ; preds = %3
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%19 = load i32, i32* %8
%20 = call i32 @snprintf(i8* %18, i32 128, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%22 = call i32 @logging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* %8
store i32 %23, i32* %4
br label %24
24: ; preds = %17, %15
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@.str.1 = [30 x i8] c"New incoming connection - %d\0A\00"
@.str.2 = [16 x i8] c"lsrp-router.log\00"
define i32 @Accept(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [128 x i8]
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %1, i32* %7
store i32 %2, i32* %5
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %5)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
13: ; preds = %3
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = call i32 @snprintf(i8* %14, i32 128, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%16 = call i32 @logging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ -1, %11 ], [ %9, %13 ]
ret i32 %18
}