#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 broadcast_loop();
int listen_loop();
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int main(const int argc, const char *argv[]) {
  char action[10] = "default";
  if (argc >= 2) {
    strncpy(action, argv[1], 10);
  }
  if (strcmp(action, "broadcast") == 0) {
    printf("broadcasting on %d\n", 9004);
    return broadcast_loop();
  } else if (strcmp(action, "listen") == 0) {
    printf("listening on %d\n", 9004);
    return listen_loop();
  } else {
    printf("unknown action\n");
    return 0;
  }
}


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)
mov    0xe93(%rip),%rax
mov    %rax,-0x1a(%rbp)
mov    0xe90(%rip),%ax
mov    %ax,-0x12(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     119c <main+0x4c>
lea    -0x1a(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    $0xa,%edx
call   1030 <strncpy@plt>
lea    -0x1a(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11d8 <main+0x88>
lea    0xe57(%rip),%rdi
mov    $0x232c,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1050 <broadcast_loop@plt>
mov    %eax,-0x4(%rbp)
jmp    1229 <main+0xd9>
lea    -0x1a(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1214 <main+0xc4>
lea    0xe36(%rip),%rdi
mov    $0x232c,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <listen_loop@plt>
mov    %eax,-0x4(%rbp)
jmp    1229 <main+0xd9>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
movabs $0x746c7561666564,%rax
mov    %rax,0x8(%rsp)
movw   $0x0,0x10(%rsp)
cmp    $0x2,%edi
jl     1192 <main+0x32>
mov    0x8(%rsi),%rsi
lea    0x8(%rsp),%rdi
mov    $0xa,%edx
call   1030 <strncpy@plt>
lea    0xe71(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11d1 <main+0x71>
lea    0xe79(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11f0 <main+0x90>
lea    0xe7b(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe3c(%rip),%rdi
mov    $0x232c,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1060 <broadcast_loop@plt>
add    $0x18,%rsp
ret
lea    0xe38(%rip),%rdi
mov    $0x232c,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <listen_loop@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@__const.main.action = [10 x i8] c"default\00\00\00"
@.str = [10 x i8] c"broadcast\00"
@.str.1 = [20 x i8] c"broadcasting on %d\0A\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [17 x i8] c"listening on %d\0A\00"
@.str.4 = [16 x i8] c"unknown action\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [10 x i8]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @strncpy(i8* %11, i8* %14, i32 10)
br label %16
16: ; preds = %10, %2
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 9004)
%22 = call i32 (...) @broadcast_loop()
store i32 %22, i32* %3
br label %32
23: ; preds = %16
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 9004)
%29 = call i32 (...) @listen_loop()
store i32 %29, i32* %3
br label %32
30: ; preds = %23
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %32
32: ; preds = %30, %27, %20
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@__const.main.action = [10 x i8] c"default\00\00\00"
@.str = [10 x i8] c"broadcast\00"
@.str.1 = [20 x i8] c"broadcasting on %d\0A\00"
@.str.2 = [7 x i8] c"listen\00"
@.str.3 = [17 x i8] c"listening on %d\0A\00"
@str = [15 x i8] c"unknown action\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strncpy(i8* %4, i8* %8, i32 10)
br label %10
10: ; preds = %6, %2
%11 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 9004)
%15 = call i32 (...) @broadcast_loop()
br label %24
16: ; preds = %10
%17 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 9004)
%21 = call i32 (...) @listen_loop()
br label %24
22: ; preds = %16
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %19, %13
%25 = phi i32 [ %15, %13 ], [ %21, %19 ], [ 0, %22 ]
ret i32 %25
}