#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*/ fflush(int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ help(char *);
scalar_t__ hub(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  char *service = NULL;
  char *env;
  env = getenv("TCPHUB_SERVICE");
  if ((env != NULL) && (strlen(env) != 0)) {
    service = malloc(strlen(env) + 1);
    if (service == NULL) {
      perror("malloc");
      return 1;
    }
    strcpy(service, env);
  }
  if (service == NULL) {
    if (argc != 2) {
      help(argv[0]);
      return 1;
    }
    service = argv[1];
  } else {
    if (argc != 1) {
      help(argv[0]);
      return 1;
    }
  }
  printf("tcphub running on port %s\n", service);
  fflush(stdout);
  if (hub(service) < 0) {
    return 1;
  }
}


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)
movq   $0x0,-0x18(%rbp)
lea    0xe4b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1225 <main+0x95>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
je     1225 <main+0x95>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0x88>
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <main+0x132>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1263 <main+0xd3>
cmpl   $0x2,-0x8(%rbp)
je     1252 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <help@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    128a <main+0xfa>
cmpl   $0x1,-0x8(%rbp)
je     1285 <main+0xf5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <help@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c2 <main+0x132>
jmp    128a <main+0xfa>
mov    -0x18(%rbp),%rsi
lea    0xd81(%rip),%rdi
call   1060 <printf@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    -0x18(%rbp),%rdi
call   10b0 <hub@plt>
cmp    $0x0,%rax
jge    12c2 <main+0x132>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11e5 <main+0x55>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11e5 <main+0x55>
add    $0x1,%rax
mov    %rax,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1232 <main+0xa2>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1040 <strcpy@plt>
cmp    $0x1,%r15d
je     11ef <main+0x5f>
jmp    121a <main+0x8a>
cmp    $0x2,%r15d
jne    121a <main+0x8a>
mov    0x8(%r14),%rbx
lea    0xe20(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   10b0 <hub@plt>
shr    $0x3f,%rax
jmp    1227 <main+0x97>
mov    (%r14),%rdi
call   10a0 <help@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd6(%rip),%rdi
call   1090 <perror@plt>
jmp    1222 <main+0x92>

LLVM IR (-O0):
@.str = [15 x i8] c"TCPHUB_SERVICE\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [27 x i8] c"tcphub running on port %s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%8 = call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = load i8*, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %28
11: ; preds = %2
%12 = load i8*, i8** %7
%13 = call i64 @strlen(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %11
%16 = load i8*, i8** %7
%17 = call i64 @strlen(i8* %16)
%18 = add nsw i64 %17, 1
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %61
24: ; preds = %15
%25 = load i8*, i8** %6
%26 = load i8*, i8** %7
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %28
28: ; preds = %24, %11, %2
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %43
31: ; preds = %28
%32 = load i32, i32* %4
%33 = icmp ne i32 %32, 2
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = call i32 @help(i8* %37)
store i32 1, i32* %3
br label %61
39: ; preds = %31
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
store i8* %42, i8** %6
br label %52
43: ; preds = %28
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %51
46: ; preds = %43
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @help(i8* %49)
store i32 1, i32* %3
br label %61
51: ; preds = %43
br label %52
52: ; preds = %51, %39
%53 = load i8*, i8** %6
%54 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @stdout
%56 = call i32 @fflush(i32 %55)
%57 = load i8*, i8** %6
%58 = call i64 @hub(i8* %57)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %52
store i32 1, i32* %3
br label %61
61: ; preds = %22, %34, %46, %60, %52
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [15 x i8] c"TCPHUB_SERVICE\00"
@.str.1 = [7 x i8] c"malloc\00"
@.str.2 = [27 x i8] c"tcphub running on port %s\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = tail call i64 @strlen(i8* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = add nsw i64 %6, 1
%10 = tail call i8* @malloc(i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %36
14: ; preds = %5, %2
%15 = icmp eq i32 %0, 2
br i1 %15, label %19, label %16
16: ; preds = %14
%17 = load i8*, i8** %1
%18 = tail call i32 @help(i8* %17)
br label %36
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
br label %28
22: ; preds = %8
%23 = tail call i32 @strcpy(i8* %10, i8* %3)
%24 = icmp eq i32 %0, 1
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %1
%27 = tail call i32 @help(i8* %26)
br label %36
28: ; preds = %22, %19
%29 = phi i8* [ %21, %19 ], [ %10, %22 ]
%30 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %29)
%31 = load i32, i32* @stdout
%32 = tail call i32 @fflush(i32 %31)
%33 = tail call i64 @hub(i8* %29)
%34 = lshr i64 %33, 63
%35 = trunc i64 %34 to i32
br label %36
36: ; preds = %28, %25, %16, %12
%37 = phi i32 [ 1, %12 ], [ 1, %16 ], [ 1, %25 ], [ %35, %28 ]
ret i32 %37
}