#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;
};
struct forth_instance {
  int dummy;
};
typedef int socklen_t;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int st_pop(struct forth_instance *);
int /*<<< orphan*/ st_push(struct forth_instance *, int);
void acceptconn(struct forth_instance *fi) {
  struct sockaddr_in their_addr;
  socklen_t tp = sizeof(struct sockaddr_in);
  int listenfd, connfd;
  listenfd = st_pop(fi);
  connfd = accept(listenfd, (struct sockaddr *)&their_addr, &tp);
  if (connfd == -1) {
    st_push(fi, (int)0);
    return;
  }
  st_push(fi, (int)connfd);
}


x86 assembly (clang, -O0):
<acceptconn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <st_pop@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117c <acceptconn+0x4c>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <st_push@plt>
jmp    1188 <acceptconn+0x58>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <st_push@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acceptconn>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x4,0x4(%rsp)
call   1030 <st_pop@plt>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %eax,%edi
call   1040 <accept@plt>
xor    %esi,%esi
cmp    $0xffffffff,%eax
cmovne %eax,%esi
mov    %rbx,%rdi
call   1050 <st_push@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.forth_instance = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define void @acceptconn(%struct.forth_instance* %0) {
%2 = alloca %struct.forth_instance*
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.forth_instance* %0, %struct.forth_instance** %2
store i32 4, i32* %4
%7 = load %struct.forth_instance*, %struct.forth_instance** %2
%8 = call i32 @st_pop(%struct.forth_instance* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %4)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load %struct.forth_instance*, %struct.forth_instance** %2
%16 = call i32 @st_push(%struct.forth_instance* %15, i32 0)
br label %21
17: ; preds = %1
%18 = load %struct.forth_instance*, %struct.forth_instance** %2
%19 = load i32, i32* %6
%20 = call i32 @st_push(%struct.forth_instance* %18, i32 %19)
br label %21
21: ; preds = %17, %14
ret void
}

LLVM IR (-O2):
%struct.forth_instance = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define void @acceptconn(%struct.forth_instance* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = tail call i32 @st_pop(%struct.forth_instance* %0)
%7 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%8 = call i32 @accept(i32 %6, %struct.sockaddr* %7, i32* %3)
%9 = icmp eq i32 %8, -1
%10 = select i1 %9, i32 0, i32 %8
%11 = call i32 @st_push(%struct.forth_instance* %0, i32 %10)
ret void
}