#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*/ LOG_ERR;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ errno;
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, ...);
int spawn(char *arguments, int fd, char *port, int *i) {
  if (strcmp(arguments, "ENDOFTRANS")) {
    syslog(LOG_INFO, "spawn argument %d: %s", *i, arguments);
    if (!strcmp(arguments, "hearts") && !(*i))
      strcpy(arguments, "diamonds");
    else if (!(strcmp(arguments, "port")) && (*i))
      strcpy(arguments, port);
    else
      strcpy(arguments, "This incident will be reported!");
    if (send(fd, arguments, 100, 0) < 0) {
      syslog(LOG_ERR, "%s", strerror(errno));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<spawn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     127b <spawn+0x12b>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rcx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11de <spawn+0x8e>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11de <spawn+0x8e>
mov    -0x8(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <strcpy@plt>
jmp    122c <spawn+0xdc>
mov    -0x8(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1217 <spawn+0xc7>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
je     1217 <spawn+0xc7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    1227 <spawn+0xd7>
mov    -0x8(%rbp),%rdi
lea    0xe14(%rip),%rsi
call   1030 <strcpy@plt>
jmp    122c <spawn+0xdc>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x0,%rax
jge    1276 <spawn+0x126>
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%edx
lea    0xdaf(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
jmp    127b <spawn+0x12b>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spawn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xe96(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1226 <spawn+0xd6>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%edx
lea    0xe80(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1060 <syslog@plt>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11af <spawn+0x5f>
cmpl   $0x0,0x0(%rbp)
je     11d4 <spawn+0x84>
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11cc <spawn+0x7c>
lea    0xe6c(%rip),%r15
jmp    11db <spawn+0x8b>
cmpl   $0x0,0x0(%rbp)
jne    11db <spawn+0x8b>
jmp    11c3 <spawn+0x73>
lea    0xe4d(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
test   %rax,%rax
jns    1226 <spawn+0xd6>
mov    0x2dc4(%rip),%rax
mov    (%rax),%ebx
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe03(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"ENDOFTRANS\00"
@LOG_INFO = global i32 0
@.str.1 = [22 x i8] c"spawn argument %d: %s\00"
@.str.2 = [7 x i8] c"hearts\00"
@.str.3 = [9 x i8] c"diamonds\00"
@.str.4 = [5 x i8] c"port\00"
@.str.5 = [32 x i8] c"This incident will be reported!\00"
@LOG_ERR = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @spawn(i8* %0, i32 %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32* %3, i32** %8
%9 = load i8*, i8** %5
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %55
12: ; preds = %4
%13 = load i32, i32* @LOG_INFO
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = load i8*, i8** %5
%17 = call i32 (i32, i8*, i32, ...) @syslog(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
%18 = load i8*, i8** %5
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %12
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = load i8*, i8** %5
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %44
28: ; preds = %21, %12
%29 = load i8*, i8** %5
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = load i32*, i32** %8
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i8*, i8** %5
%38 = load i8*, i8** %7
%39 = call i32 @strcpy(i8* %37, i8* %38)
br label %43
40: ; preds = %32, %28
%41 = load i8*, i8** %5
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
br label %43
43: ; preds = %40, %36
br label %44
44: ; preds = %43, %25
%45 = load i32, i32* %6
%46 = load i8*, i8** %5
%47 = call i64 @send(i32 %45, i8* %46, i32 100, i32 0)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %44
%50 = load i32, i32* @LOG_ERR
%51 = load i32, i32* @errno
%52 = call i32 @strerror(i32 %51)
%53 = call i32 (i32, i8*, i32, ...) @syslog(i32 %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %49, %44
br label %55
55: ; preds = %54, %4
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"ENDOFTRANS\00"
@LOG_INFO = global i32 0
@.str.1 = [22 x i8] c"spawn argument %d: %s\00"
@.str.2 = [7 x i8] c"hearts\00"
@.str.3 = [9 x i8] c"diamonds\00"
@.str.4 = [5 x i8] c"port\00"
@.str.5 = [32 x i8] c"This incident will be reported!\00"
@LOG_ERR = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @spawn(i8* %0, i32 %1, i8* %2, i32* nocapture %3) {
%5 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %33, label %7
7: ; preds = %4
%8 = load i32, i32* @LOG_INFO
%9 = load i32, i32* %3
%10 = tail call i32 (i32, i8*, i32, ...) @syslog(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %9, i8* %0)
%11 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %13, %7
%17 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19, %16
br label %23
23: ; preds = %19, %13, %22
%24 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), %22 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), %13 ], [ %2, %19 ]
%25 = tail call i32 @strcpy(i8* %0, i8* %24)
%26 = tail call i64 @send(i32 %1, i8* %0, i32 100, i32 0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = load i32, i32* @LOG_ERR
%30 = load i32, i32* @errno
%31 = tail call i32 @strerror(i32 %30)
%32 = tail call i32 (i32, i8*, i32, ...) @syslog(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %23, %28, %4
ret i32 0
}