#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 /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ exec_socat(char *);
int fork_daemon(int, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sigignore(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unused(char *, ...);
int main(int argc, char **argv) {
  for (int i = 0; i < argc; ++i) {
    do {
      unused("argv[%i] = %s", i, argv[i]);
    } while (0);
  }
  int rc = 1;
  if (argc < 4) {
    fprintf(stderr, "Usage: %s SOCAT_ADDRESS ZEROMQ_ENDPOINT PGM [ARGS]...\n",
            argv[0]);
    goto _out;
  }
  if (sigignore(SIGCHLD) == -1) {
    do {
      unused("sigignore(SIGCHLD) failed");
    } while (0);
    goto _out;
  }
  if (fork_daemon(argc - 2, argv + 2) == -1)
    goto _out;
  exec_socat(argv[1]);
_out:
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ae <main+0x5e>
jmp    117e <main+0x2e>
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
jmp    11a0 <main+0x50>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
movl   $0x1,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11e0 <main+0x90>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
jmp    123d <main+0xed>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1030 <sigignore@plt>
cmp    $0xffffffff,%eax
jne    120f <main+0xbf>
jmp    11fc <main+0xac>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <unused@plt>
jmp    123d <main+0xed>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
mov    -0x10(%rbp),%rsi
add    $0x10,%rsi
call   1040 <fork_daemon@plt>
cmp    $0xffffffff,%eax
jne    1230 <main+0xe0>
jmp    123d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <exec_socat@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
test   %edi,%edi
jle    118e <main+0x3e>
mov    %edi,%r14d
mov    %edi,%ebx
lea    0xe95(%rip),%r15
xor    %ebp,%ebp
nopl   (%rax)
mov    (%r12,%rbp,8),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <unused@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <main+0x20>
cmp    $0x4,%ebx
jge    11b5 <main+0x65>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe6c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
call   1030 <sigignore@plt>
cmp    $0xffffffff,%eax
je     11ea <main+0x9a>
add    $0xfffffffe,%r14d
lea    0x10(%r12),%rsi
mov    %r14d,%edi
call   1040 <fork_daemon@plt>
cmp    $0xffffffff,%eax
je     11a7 <main+0x57>
mov    0x8(%r12),%rdi
call   1070 <exec_socat@plt>
jmp    11a7 <main+0x57>
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1050 <unused@plt>
jmp    11a7 <main+0x57>

LLVM IR (-O0):
@.str = [14 x i8] c"argv[%i] = %s\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"Usage: %s SOCAT_ADDRESS ZEROMQ_ENDPOINT PGM [ARGS]...\0A\00"
@SIGCHLD = global i32 0
@.str.2 = [26 x i8] c"sigignore(SIGCHLD) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %22, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %25
12: ; preds = %8
br label %13
13: ; preds = %12
%14 = load i32, i32* %6
%15 = load i8**, i8*** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %19)
br label %21
21: ; preds = %13
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %8
25: ; preds = %8
store i32 1, i32* %7
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %55
34: ; preds = %25
%35 = load i32, i32* @SIGCHLD
%36 = call i32 @sigignore(i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %42
38: ; preds = %34
br label %39
39: ; preds = %38
%40 = call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39
br label %55
42: ; preds = %34
%43 = load i32, i32* %4
%44 = sub nsw i32 %43, 2
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = call i32 @fork_daemon(i32 %44, i8** %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %50
49: ; preds = %42
br label %55
50: ; preds = %42
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @exec_socat(i8* %53)
br label %55
55: ; preds = %50, %49, %41, %28
%56 = load i32, i32* %7
ret i32 %56
}

LLVM IR (-O2):
@.str = [14 x i8] c"argv[%i] = %s\00"
@stderr = global i32 0
@.str.1 = [55 x i8] c"Usage: %s SOCAT_ADDRESS ZEROMQ_ENDPOINT PGM [ARGS]...\0A\00"
@SIGCHLD = global i32 0
@.str.2 = [26 x i8] c"sigignore(SIGCHLD) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %8
6: ; preds = %8
%7 = icmp slt i32 %0, 4
br i1 %7, label %16, label %20
8: ; preds = %4, %8
%9 = phi i64 [ 0, %4 ], [ %14, %8 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = trunc i64 %9 to i32
%13 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %11)
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %5
br i1 %15, label %6, label %8
16: ; preds = %2, %6
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %35
20: ; preds = %6
%21 = load i32, i32* @SIGCHLD
%22 = tail call i32 @sigignore(i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 (i8*, ...) @unused(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %35
26: ; preds = %20
%27 = add nsw i32 %0, -2
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = tail call i32 @fork_daemon(i32 %27, i8** %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = tail call i32 @exec_socat(i8* %33)
br label %35
35: ; preds = %26, %31, %24, %16
ret i32 1
}