#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*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ test_bind(int);
scalar_t__ test_connect(char *, int);
int main(int argc, char *argv[]) {
  printf("Userlevel Firewall Test Application!\n");
  printf("bind to port 1234: ");
  if (test_bind(1234) < 0) {
    printf("failed!\n");
    perror("cause");
    return 1;
  }
  printf("succeeded\n");
  printf("bind to port 4321 (expect failure): ");
  if (test_bind(4321) == 0) {
    printf("succeeded!\n");
    return 1;
  }
  printf("failed\n");
  printf("connect to www.scs.stanford.edu(171.66.3.9):80: ");
  if (test_connect("171.66.3.9", 80) < 0) {
    printf("failed!\n");
    perror("cause");
    return 1;
  }
  printf("succeeded\n");
  printf("connect to market.scs.stanford.edu(171.66.3.10):22: ");
  if (test_connect("171.66.3.10", 22) == 0) {
    printf("succeeded!\n");
    return 1;
  }
  printf("failed\n");
  printf("all tests passed!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xebd(%rip),%rdi
call   1040 <printf@plt>
mov    $0x4d2,%edi
call   1050 <test_bind@plt>
cmp    $0x0,%rax
jge    11a6 <main+0x66>
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <main+0x16b>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x10e1,%edi
call   1050 <test_bind@plt>
cmp    $0x0,%rax
jne    11ea <main+0xaa>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <main+0x16b>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x50,%esi
call   1030 <test_connect@plt>
cmp    $0x0,%rax
jge    1241 <main+0x101>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
call   1060 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <main+0x16b>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x16,%esi
call   1030 <test_connect@plt>
cmp    $0x0,%rax
jne    128c <main+0x14c>
lea    0xdfe(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ab <main+0x16b>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xf64(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x4d2,%edi
call   1060 <test_bind@plt>
test   %rax,%rax
js     122e <main+0xde>
lea    0xf5e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x10e1,%edi
call   1060 <test_bind@plt>
test   %rax,%rax
je     121b <main+0xcb>
lea    0xf41(%rip),%rdi
call   1030 <puts@plt>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x50,%esi
call   1040 <test_connect@plt>
test   %rax,%rax
js     122e <main+0xde>
lea    0xf09(%rip),%rdi
call   1030 <puts@plt>
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
mov    $0x16,%esi
call   1040 <test_connect@plt>
test   %rax,%rax
je     121b <main+0xcb>
lea    0xee5(%rip),%rdi
call   1030 <puts@plt>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
lea    0xdd3(%rip),%rdi
call   1070 <perror@plt>
jmp    1227 <main+0xd7>

LLVM IR (-O0):
@.str = [38 x i8] c"Userlevel Firewall Test Application!\0A\00"
@.str.1 = [20 x i8] c"bind to port 1234: \00"
@.str.2 = [9 x i8] c"failed!\0A\00"
@.str.3 = [6 x i8] c"cause\00"
@.str.4 = [11 x i8] c"succeeded\0A\00"
@.str.5 = [37 x i8] c"bind to port 4321 (expect failure): \00"
@.str.6 = [12 x i8] c"succeeded!\0A\00"
@.str.7 = [8 x i8] c"failed\0A\00"
@.str.8 = [49 x i8] c"connect to www.scs.stanford.edu(171.66.3.9):80: \00"
@.str.9 = [11 x i8] c"171.66.3.9\00"
@.str.10 = [53 x i8] c"connect to market.scs.stanford.edu(171.66.3.10):22: \00"
@.str.11 = [12 x i8] c"171.66.3.10\00"
@.str.12 = [19 x i8] c"all tests passed!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%8 = call i64 @test_bind(i32 1234)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %38
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%16 = call i64 @test_bind(i32 4321)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %38
20: ; preds = %13
%21 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%22 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%23 = call i64 @test_connect(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 80)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %38
28: ; preds = %20
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%31 = call i64 @test_connect(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 22)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %38
35: ; preds = %28
%36 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%37 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
store i32 0, i32* %3
br label %38
38: ; preds = %35, %33, %25, %18, %10
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"bind to port 1234: \00"
@.str.3 = [6 x i8] c"cause\00"
@.str.5 = [37 x i8] c"bind to port 4321 (expect failure): \00"
@.str.8 = [49 x i8] c"connect to www.scs.stanford.edu(171.66.3.9):80: \00"
@.str.9 = [11 x i8] c"171.66.3.9\00"
@.str.10 = [53 x i8] c"connect to market.scs.stanford.edu(171.66.3.10):22: \00"
@.str.11 = [12 x i8] c"171.66.3.10\00"
@str = [37 x i8] c"Userlevel Firewall Test Application!\00"
@str.15 = [10 x i8] c"succeeded\00"
@str.16 = [7 x i8] c"failed\00"
@str.17 = [18 x i8] c"all tests passed!\00"
@str.20 = [11 x i8] c"succeeded!\00"
@str.21 = [8 x i8] c"failed!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i64 @test_bind(i32 1234)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.21, i64 0, i64 0))
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %35
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.15, i64 0, i64 0))
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%13 = tail call i64 @test_bind(i32 4321)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.20, i64 0, i64 0))
br label %35
17: ; preds = %10
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.16, i64 0, i64 0))
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.8, i64 0, i64 0))
%20 = tail call i64 @test_connect(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 80)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.21, i64 0, i64 0))
%24 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %35
25: ; preds = %17
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.15, i64 0, i64 0))
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.10, i64 0, i64 0))
%28 = tail call i64 @test_connect(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 22)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.20, i64 0, i64 0))
br label %35
32: ; preds = %25
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.16, i64 0, i64 0))
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.17, i64 0, i64 0))
br label %35
35: ; preds = %32, %30, %22, %15, %7
%36 = phi i32 [ 1, %7 ], [ 1, %15 ], [ 1, %22 ], [ 1, %30 ], [ 0, %32 ]
ret i32 %36
}