#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 */

/* Variables and functions */
int atoi(char *);
int *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int *parse_listen_fds_env(char *listen_fds_env, int fd_count) {
  int *listen_fds = calloc(fd_count, sizeof(int));
  if (listen_fds == NULL) {
    fprintf(stderr, "failed to allocated mem for listen fds, aborting ...");
    exit(1);
  }
  char *iter = listen_fds_env;
  char *cur = listen_fds_env;
  int fd_iter = 0;
  while (*cur != '\0') {
    while (*cur != '\0' && *cur != ' ') {
      ++cur;
    }
    int fd = atoi(iter);
    listen_fds[fd_iter] = fd;
    ++fd_iter;
    if (*cur == '\0') {
      break;
    }
    ++cur;
    iter = cur;
  }
  return listen_fds;
}


x86 assembly (clang, -O0):
<parse_listen_fds_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118a <parse_listen_fds_env+0x4a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124d <parse_listen_fds_env+0x10d>
jmp    11b6 <parse_listen_fds_env+0x76>
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     11db <parse_listen_fds_env+0x9b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11eb <parse_listen_fds_env+0xab>
jmp    11fc <parse_listen_fds_env+0xbc>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11b6 <parse_listen_fds_env+0x76>
mov    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edx
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1234 <parse_listen_fds_env+0xf4>
jmp    124d <parse_listen_fds_env+0x10d>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11a1 <parse_listen_fds_env+0x61>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_listen_fds_env>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %esi,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     11bc <parse_listen_fds_env+0x7c>
mov    %rax,%r14
xor    %r12d,%r12d
jmp    1189 <parse_listen_fds_env+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r14,%r12,4)
add    $0x1,%r12
cmpb   $0x0,-0x1(%rbx)
mov    %rbx,%r15
je     11ad <parse_listen_fds_env+0x6d>
mov    (%r15),%al
test   %al,%al
je     11ad <parse_listen_fds_env+0x6d>
lea    0x1(%r15),%rbx
test   $0xdf,%al
je     1170 <parse_listen_fds_env+0x30>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   $0xdf,%al
jne    11a0 <parse_listen_fds_env+0x60>
jmp    1170 <parse_listen_fds_env+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"failed to allocated mem for listen fds, aborting ...\00"
define i32* @parse_listen_fds_env(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = load i32, i32* %4
%11 = call i32* @calloc(i32 %10, i32 4)
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8*, i8** %3
store i8* %19, i8** %6
%20 = load i8*, i8** %3
store i8* %20, i8** %7
store i32 0, i32* %8
br label %21
21: ; preds = %57, %18
%22 = load i8*, i8** %7
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %61
26: ; preds = %21
br label %27
27: ; preds = %39, %26
%28 = load i8*, i8** %7
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 32
br label %37
37: ; preds = %32, %27
%38 = phi i1 [ false, %27 ], [ %36, %32 ]
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %7
br label %27
42: ; preds = %37
%43 = load i8*, i8** %6
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = load i32*, i32** %5
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %42
br label %61
57: ; preds = %42
%58 = load i8*, i8** %7
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %7
%60 = load i8*, i8** %7
store i8* %60, i8** %6
br label %21
61: ; preds = %56, %21
%62 = load i32*, i32** %5
ret i32* %62
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"failed to allocated mem for listen fds, aborting ...\00"
define noalias i32* @parse_listen_fds_env(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @calloc(i32 %1, i32 4)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2, %20
%10 = phi i64 [ %23, %20 ], [ 0, %2 ]
%11 = phi i8* [ %26, %20 ], [ %0, %2 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %9, %17
%15 = phi i8 [ %19, %17 ], [ %12, %9 ]
%16 = phi i8* [ %18, %17 ], [ %11, %9 ]
switch i8 %15, label %17 [
i8 0, label %20
i8 32, label %20
]
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %16, i64 1
%19 = load i8, i8* %18
br label %14
20: ; preds = %14, %14
%21 = tail call i32 @atoi(i8* %11)
%22 = getelementptr inbounds i32, i32* %3, i64 %10
store i32 %21, i32* %22
%23 = add nuw i64 %10, 1
%24 = load i8, i8* %16
%25 = icmp eq i8 %24, 0
%26 = getelementptr inbounds i8, i8* %16, i64 1
br i1 %25, label %27, label %9
27: ; preds = %20, %9
ret i32* %3
}