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

/* Variables and functions */
int /*<<< orphan*/ FD_CLR(int, int /*<<< orphan*/ *);
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fuse_add_client(int);
int fuse_process_client_fds(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ sleep(int);
int fuse_scan_extra_fds(int command_fd, fd_set *set, int *max_fd) {
  struct sockaddr_un new_addr;
  socklen_t new_len = sizeof(struct sockaddr_un);
  int new_fd;
  if (FD_ISSET(command_fd, set)) {
    new_fd = accept(command_fd, (struct sockaddr *)&new_addr, &new_len);
    if (new_fd >= 0) {
      fuse_add_client(new_fd);
      FD_SET(new_fd, set);
      if ((new_fd + 1) > *max_fd)
        *max_fd = new_fd + 1;
    }
  }
  switch (fuse_process_client_fds(set, *max_fd)) {
  case -1: {
    int i;
    FD_CLR(new_fd, set);
    for (i = *max_fd; i >= 0; i--)
      if (FD_ISSET(i, set)) {
        *max_fd = i;
        break;
      }
  }
    (*max_fd)++;
    close(new_fd);
    goto out;
  case 1:
    goto out;
  }
  sleep(10);
  return 0;
out:
  return 1;
}


x86 assembly (clang, -O0):
<fuse_scan_extra_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1209 <fuse_scan_extra_fds+0x89>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1204 <fuse_scan_extra_fds+0x84>
mov    -0x28(%rbp),%edi
call   1050 <fuse_add_client@plt>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1090 <FD_SET@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    11ff <fuse_scan_extra_fds+0x7f>
mov    -0x28(%rbp),%ecx
add    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1204 <fuse_scan_extra_fds+0x84>
jmp    1209 <fuse_scan_extra_fds+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <fuse_process_client_fds@plt>
mov    %eax,%ecx
mov    %ecx,-0x30(%rbp)
sub    $0xffffffff,%eax
je     123c <fuse_scan_extra_fds+0xbc>
jmp    122b <fuse_scan_extra_fds+0xab>
mov    -0x30(%rbp),%eax
sub    $0x1,%eax
je     12aa <fuse_scan_extra_fds+0x12a>
jmp    12af <fuse_scan_extra_fds+0x12f>
mov    -0x28(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <FD_CLR@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1292 <fuse_scan_extra_fds+0x112>
mov    -0x2c(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     127f <fuse_scan_extra_fds+0xff>
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1292 <fuse_scan_extra_fds+0x112>
jmp    1284 <fuse_scan_extra_fds+0x104>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    1251 <fuse_scan_extra_fds+0xd1>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
jmp    12c5 <fuse_scan_extra_fds+0x145>
jmp    12c5 <fuse_scan_extra_fds+0x145>
mov    $0xa,%edi
call   10a0 <sleep@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cc <fuse_scan_extra_fds+0x14c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuse_scan_extra_fds>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11df <fuse_scan_extra_fds+0x5f>
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %ebp,%edi
call   1070 <accept@plt>
mov    %eax,%r15d
test   %eax,%eax
js     11df <fuse_scan_extra_fds+0x5f>
mov    %r15d,%edi
call   1050 <fuse_add_client@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1090 <FD_SET@plt>
cmp    (%r14),%r15d
jl     11df <fuse_scan_extra_fds+0x5f>
mov    %r15d,%eax
add    $0x1,%eax
mov    %eax,(%r14)
jmp    11df <fuse_scan_extra_fds+0x5f>
mov    (%r14),%esi
mov    %rbx,%rdi
call   1060 <fuse_process_client_fds@plt>
cmp    $0x1,%eax
je     124c <fuse_scan_extra_fds+0xcc>
cmp    $0xffffffff,%eax
jne    1240 <fuse_scan_extra_fds+0xc0>
mov    %r15d,%edi
mov    %rbx,%rsi
call   1080 <FD_CLR@plt>
mov    (%r14),%ebp
test   %ebp,%ebp
js     122b <fuse_scan_extra_fds+0xab>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    122b <fuse_scan_extra_fds+0xab>
lea    -0x1(%rbp),%eax
test   %ebp,%ebp
mov    %eax,%ebp
jg     1210 <fuse_scan_extra_fds+0x90>
mov    (%r14),%ebp
add    $0x1,%ebp
mov    %ebp,(%r14)
mov    %r15d,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    124c <fuse_scan_extra_fds+0xcc>
mov    $0xa,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @fuse_scan_extra_fds(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.sockaddr_un
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 4, i32* %9
%12 = load i32, i32* %5
%13 = load i32*, i32** %6
%14 = call i64 @FD_ISSET(i32 %12, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %3
%17 = load i32, i32* %5
%18 = bitcast %struct.sockaddr_un* %8 to %struct.sockaddr*
%19 = call i32 @accept(i32 %17, %struct.sockaddr* %18, i32* %9)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %16
%23 = load i32, i32* %10
%24 = call i32 @fuse_add_client(i32 %23)
%25 = load i32, i32* %10
%26 = load i32*, i32** %6
%27 = call i32 @FD_SET(i32 %25, i32* %26)
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
%30 = load i32*, i32** %7
%31 = load i32, i32* %30
%32 = icmp sgt i32 %29, %31
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
%36 = load i32*, i32** %7
store i32 %35, i32* %36
br label %37
37: ; preds = %33, %22
br label %38
38: ; preds = %37, %16
br label %39
39: ; preds = %38, %3
%40 = load i32*, i32** %6
%41 = load i32*, i32** %7
%42 = load i32, i32* %41
%43 = call i32 @fuse_process_client_fds(i32* %40, i32 %42)
switch i32 %43, label %72 [
i32 -1, label %44
i32 1, label %71
]
44: ; preds = %39
%45 = load i32, i32* %10
%46 = load i32*, i32** %6
%47 = call i32 @FD_CLR(i32 %45, i32* %46)
%48 = load i32*, i32** %7
%49 = load i32, i32* %48
store i32 %49, i32* %11
br label %50
50: ; preds = %62, %44
%51 = load i32, i32* %11
%52 = icmp sge i32 %51, 0
br i1 %52, label %53, label %65
53: ; preds = %50
%54 = load i32, i32* %11
%55 = load i32*, i32** %6
%56 = call i64 @FD_ISSET(i32 %54, i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* %11
%60 = load i32*, i32** %7
store i32 %59, i32* %60
br label %65
61: ; preds = %53
br label %62
62: ; preds = %61
%63 = load i32, i32* %11
%64 = add nsw i32 %63, -1
store i32 %64, i32* %11
br label %50
65: ; preds = %58, %50
%66 = load i32*, i32** %7
%67 = load i32, i32* %66
%68 = add nsw i32 %67, 1
store i32 %68, i32* %66
%69 = load i32, i32* %10
%70 = call i32 @close(i32 %69)
br label %74
71: ; preds = %39
br label %74
72: ; preds = %39
%73 = call i32 @sleep(i32 10)
store i32 0, i32* %4
br label %75
74: ; preds = %71, %65
store i32 1, i32* %4
br label %75
75: ; preds = %74, %72
%76 = load i32, i32* %4
ret i32 %76
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @fuse_scan_extra_fds(i32 %0, i32* %1, i32* nocapture %2) {
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
%6 = bitcast %struct.sockaddr_un* %4 to i8*
%7 = bitcast i32* %5 to i8*
store i32 4, i32* %5
%8 = tail call i64 @FD_ISSET(i32 %0, i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %3
%11 = bitcast %struct.sockaddr_un* %4 to %struct.sockaddr*
%12 = call i32 @accept(i32 %0, %struct.sockaddr* %11, i32* %5)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %10
%15 = call i32 @fuse_add_client(i32 %12)
%16 = call i32 @FD_SET(i32 %12, i32* %1)
%17 = load i32, i32* %2
%18 = icmp slt i32 %12, %17
br i1 %18, label %21, label %19
19: ; preds = %14
%20 = add nuw nsw i32 %12, 1
store i32 %20, i32* %2
br label %21
21: ; preds = %10, %19, %14, %3
%22 = phi i32 [ %12, %19 ], [ %12, %14 ], [ %12, %10 ], [ undef, %3 ]
%23 = load i32, i32* %2
%24 = call i32 @fuse_process_client_fds(i32* %1, i32 %23)
switch i32 %24, label %42 [
i32 -1, label %25
i32 1, label %44
]
25: ; preds = %21
%26 = call i32 @FD_CLR(i32 %22, i32* %1)
%27 = load i32, i32* %2
%28 = icmp sgt i32 %27, -1
br i1 %28, label %29, label %38
29: ; preds = %25, %33
%30 = phi i32 [ %34, %33 ], [ %27, %25 ]
%31 = call i64 @FD_ISSET(i32 %30, i32* %1)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = add nsw i32 %30, -1
%35 = icmp sgt i32 %30, 0
br i1 %35, label %29, label %36
36: ; preds = %33
%37 = load i32, i32* %2
br label %38
38: ; preds = %29, %36, %25
%39 = phi i32 [ %37, %36 ], [ %27, %25 ], [ %30, %29 ]
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
%41 = call i32 @close(i32 %22)
br label %44
42: ; preds = %21
%43 = call i32 @sleep(i32 10)
br label %44
44: ; preds = %38, %21, %42
%45 = phi i32 [ 0, %42 ], [ %24, %21 ], [ 1, %38 ]
ret i32 %45
}