#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 socklen_t;
typedef int /*<<< orphan*/ cip;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ perror(char *);
void run(int sfd) {
  for (;;) {
    int cfd;
    struct sockaddr_in cip;
    socklen_t clen = sizeof(cip);
    cfd = accept(sfd, (struct sockaddr *)&cip, &clen);
    if (-1 == cfd) {
      perror("accept");
      continue;
    }
    close(cfd);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1174 <run+0x44>
lea    0xe96(%rip),%rdi
call   1040 <perror@plt>
jmp    113b <run+0xb>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
jmp    113b <run+0xb>

x86 assembly (clang, -O2):
<run>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0xeb2(%rip),%r12
jmp    1158 <run+0x28>
mov    %r12,%rdi
call   1040 <perror@plt>
movl   $0x4,0xc(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <accept@plt>
cmp    $0xffffffff,%eax
je     1150 <run+0x20>
mov    %eax,%edi
call   1030 <close@plt>
jmp    1158 <run+0x28>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
define void @run(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %14, %12, %1
store i32 4, i32* %5
%7 = load i32, i32* %2
%8 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%9 = call i32 @accept(i32 %7, %struct.sockaddr* %8, i32* %5)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %6
14: ; preds = %6
%15 = load i32, i32* %3
%16 = call i32 @close(i32 %15)
br label %6
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
define void @run(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
br label %7
7: ; preds = %14, %1
store i32 4, i32* %3
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %14
12: ; preds = %7
%13 = call i32 @close(i32 %8)
br label %14
14: ; preds = %12, %10
br label %7
}