#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 INET6_ADDRSTRLEN;
int /*<<< orphan*/ broadcaster();
int /*<<< orphan*/ client(char *, int *, char *);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ listener(char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ server(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int port;
  char ip[INET6_ADDRSTRLEN];
  if (argc > 1) {
    printf("Listening for request..\n");
    listener(ip, &port);
    printf("Sending file to: %s:%d\n", ip, port);
    client(ip, &port, argv[1]);
  } else {
    printf("Requesting file..\n");
    if (!fork()) {
      server(10789);
    } else {
      sleep(1);
      broadcaster();
      int status;
      wait(&status);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1216 <main+0x96>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <listener@plt>
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    -0x14(%rbp),%rsi
call   1070 <client@plt>
jmp    1262 <main+0xe2>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    1243 <main+0xc3>
mov    $0x2a25,%edi
call   1050 <server@plt>
jmp    125d <main+0xdd>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    $0x0,%al
call   1030 <broadcaster@plt>
lea    -0x2c(%rbp),%rdi
call   1090 <wait@plt>
jmp    1262 <main+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%r12
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmp    $0x2,%edi
jl     1204 <main+0x74>
mov    %rsi,%r14
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
lea    -0x24(%rbp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <listener@plt>
mov    -0x24(%rbp),%edx
lea    0xe17(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <client@plt>
jmp    1241 <main+0xb1>
lea    0xe0d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1237 <main+0xa7>
mov    $0x1,%edi
call   1090 <sleep@plt>
xor    %eax,%eax
call   1040 <broadcaster@plt>
lea    -0x28(%rbp),%rdi
call   10a0 <wait@plt>
jmp    1241 <main+0xb1>
mov    $0x2a25,%edi
call   1060 <server@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INET6_ADDRSTRLEN = global i32 0
@.str = [25 x i8] c"Listening for request..\0A\00"
@.str.1 = [24 x i8] c"Sending file to: %s:%d\0A\00"
@.str.2 = [19 x i8] c"Requesting file..\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @INET6_ADDRSTRLEN
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %7
%13 = alloca i8, i64 %11
store i64 %11, i64* %8
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %25
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @listener(i8* %13, i32* %6)
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %13, i32 %19)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @client(i8* %13, i32* %6, i8* %23)
br label %36
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 (...) @fork()
%28 = icmp ne i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 @server(i32 10789)
br label %35
31: ; preds = %25
%32 = call i32 @sleep(i32 1)
%33 = call i32 (...) @broadcaster()
%34 = call i32 @wait(i32* %9)
br label %35
35: ; preds = %31, %29
br label %36
36: ; preds = %35, %16
store i32 0, i32* %3
%37 = load i8*, i8** %7
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@INET6_ADDRSTRLEN = global i32 0
@.str.1 = [24 x i8] c"Sending file to: %s:%d\0A\00"
@str = [18 x i8] c"Requesting file..\00"
@str.3 = [24 x i8] c"Listening for request..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @INET6_ADDRSTRLEN
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = icmp sgt i32 %0, 1
br i1 %10, label %11, label %19
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.3, i64 0, i64 0))
%13 = call i32 @listener(i8* %9, i32* %3)
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32 %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @client(i8* %9, i32* %3, i8* %17)
br label %30
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 @server(i32 10789)
br label %30
25: ; preds = %19
%26 = tail call i32 @sleep(i32 1)
%27 = tail call i32 (...) @broadcaster()
%28 = bitcast i32* %4 to i8*
%29 = call i32 @wait(i32* %4)
br label %30
30: ; preds = %23, %25, %11
ret i32 0
}