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

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ sockaddr_tostring(struct sockaddr_storage *, char *, int,
                                     int *);
int tcp_accept(char *err, int sfd, char *ip, int ip_len, int *port) {
  int fd;
  struct sockaddr_storage sa;
  socklen_t salen = sizeof(sa);
  fd = accept(sfd, (struct sockaddr *)&sa, &salen);
  if (fd != -1) {
    sockaddr_tostring(&sa, ip, ip_len, port);
  }
  return fd;
}


x86 assembly (clang, -O0):
<tcp_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x4,-0x34(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
je     1172 <tcp_accept+0x52>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
call   1030 <sockaddr_tostring@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_accept>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%rbx
mov    %esi,%edi
movl   $0x4,0x4(%rsp)
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1040 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     115f <tcp_accept+0x3f>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1030 <sockaddr_tostring@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @tcp_accept(i8* %0, i32 %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca %struct.sockaddr_storage
%13 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
store i32 4, i32* %13
%14 = load i32, i32* %7
%15 = bitcast %struct.sockaddr_storage* %12 to %struct.sockaddr*
%16 = call i32 @accept(i32 %14, %struct.sockaddr* %15, i32* %13)
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %5
%20 = load i8*, i8** %8
%21 = load i32, i32* %9
%22 = load i32*, i32** %10
%23 = call i32 @sockaddr_tostring(%struct.sockaddr_storage* %12, i8* %20, i32 %21, i32* %22)
br label %24
24: ; preds = %19, %5
%25 = load i32, i32* %11
ret i32 %25
}

LLVM IR (-O2):
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @tcp_accept(i8* nocapture readnone %0, i32 %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = bitcast %struct.sockaddr_storage* %6 to i8*
%9 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%10 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%11 = call i32 @accept(i32 %1, %struct.sockaddr* %10, i32* %7)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = call i32 @sockaddr_tostring(%struct.sockaddr_storage* %6, i8* %2, i32 %3, i32* %4)
br label %15
15: ; preds = %13, %5
ret i32 %11
}