#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*/ EADDRINUSE;
int /*<<< orphan*/ ipdivert_bind(char const *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ ipdivert_close(char const *, int);
int ipdivert_create(char const *);
int /*<<< orphan*/ ok(char const *);
int main(int argc, char *argv[]) {
  const char *test;
  int s1, s2;
  test = "create_close";
  s1 = ipdivert_create(test);
  ipdivert_close(test, s1);
  ok(test);
  test = "create_bind_close";
  s1 = ipdivert_create(test);
  ipdivert_bind(test, s1, 1000, 0);
  ipdivert_close(test, s1);
  ok(test);
  test = "create2_bind2_close2";
  s1 = ipdivert_create(test);
  s2 = ipdivert_create(test);
  ipdivert_bind(test, s1, 1000, 0);
  ipdivert_bind(test, s2, 1001, 0);
  ipdivert_close(test, s1);
  ipdivert_close(test, s2);
  ok(test);
  test = "create2_bind2_conflict_close2";
  s1 = ipdivert_create(test);
  s2 = ipdivert_create(test);
  ipdivert_bind(test, s1, 1000, 0);
  ipdivert_bind(test, s2, 1000, EADDRINUSE);
  ipdivert_close(test, s1);
  ipdivert_close(test, s2);
  ok(test);
  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)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ok@plt>
lea    0xe84(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ok@plt>
lea    0xe57(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    $0x3e9,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ok@plt>
lea    0xe02(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    0x2d71(%rip),%rax
mov    (%rax),%ecx
mov    $0x3e8,%edx
call   1050 <ipdivert_bind@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <ipdivert_close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <ok@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xeb5(%rip),%rbx
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
call   1030 <ok@plt>
lea    0xea1(%rip),%rbx
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
call   1030 <ok@plt>
lea    0xe7f(%rip),%rbx
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x3e9,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
call   1030 <ok@plt>
lea    0xe38(%rip),%rbx
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <ipdivert_create@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1050 <ipdivert_bind@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x3e8,%edx
call   1050 <ipdivert_bind@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <ipdivert_close@plt>
mov    %rbx,%rdi
call   1030 <ok@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"create_close\00"
@.str.1 = [18 x i8] c"create_bind_close\00"
@.str.2 = [21 x i8] c"create2_bind2_close2\00"
@.str.3 = [30 x i8] c"create2_bind2_conflict_close2\00"
@EADDRINUSE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8** %6
%9 = load i8*, i8** %6
%10 = call i32 @ipdivert_create(i8* %9)
store i32 %10, i32* %7
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @ipdivert_close(i8* %11, i32 %12)
%14 = load i8*, i8** %6
%15 = call i32 @ok(i8* %14)
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %6
%16 = load i8*, i8** %6
%17 = call i32 @ipdivert_create(i8* %16)
store i32 %17, i32* %7
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = call i32 @ipdivert_bind(i8* %18, i32 %19, i32 1000, i32 0)
%21 = load i8*, i8** %6
%22 = load i32, i32* %7
%23 = call i32 @ipdivert_close(i8* %21, i32 %22)
%24 = load i8*, i8** %6
%25 = call i32 @ok(i8* %24)
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8** %6
%26 = load i8*, i8** %6
%27 = call i32 @ipdivert_create(i8* %26)
store i32 %27, i32* %7
%28 = load i8*, i8** %6
%29 = call i32 @ipdivert_create(i8* %28)
store i32 %29, i32* %8
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = call i32 @ipdivert_bind(i8* %30, i32 %31, i32 1000, i32 0)
%33 = load i8*, i8** %6
%34 = load i32, i32* %8
%35 = call i32 @ipdivert_bind(i8* %33, i32 %34, i32 1001, i32 0)
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @ipdivert_close(i8* %36, i32 %37)
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = call i32 @ipdivert_close(i8* %39, i32 %40)
%42 = load i8*, i8** %6
%43 = call i32 @ok(i8* %42)
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8** %6
%44 = load i8*, i8** %6
%45 = call i32 @ipdivert_create(i8* %44)
store i32 %45, i32* %7
%46 = load i8*, i8** %6
%47 = call i32 @ipdivert_create(i8* %46)
store i32 %47, i32* %8
%48 = load i8*, i8** %6
%49 = load i32, i32* %7
%50 = call i32 @ipdivert_bind(i8* %48, i32 %49, i32 1000, i32 0)
%51 = load i8*, i8** %6
%52 = load i32, i32* %8
%53 = load i32, i32* @EADDRINUSE
%54 = call i32 @ipdivert_bind(i8* %51, i32 %52, i32 1000, i32 %53)
%55 = load i8*, i8** %6
%56 = load i32, i32* %7
%57 = call i32 @ipdivert_close(i8* %55, i32 %56)
%58 = load i8*, i8** %6
%59 = load i32, i32* %8
%60 = call i32 @ipdivert_close(i8* %58, i32 %59)
%61 = load i8*, i8** %6
%62 = call i32 @ok(i8* %61)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"create_close\00"
@.str.1 = [18 x i8] c"create_bind_close\00"
@.str.2 = [21 x i8] c"create2_bind2_close2\00"
@.str.3 = [30 x i8] c"create2_bind2_conflict_close2\00"
@EADDRINUSE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @ok(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @ipdivert_bind(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 1000, i32 0)
%8 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%9 = tail call i32 @ok(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @ipdivert_bind(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 1000, i32 0)
%13 = tail call i32 @ipdivert_bind(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 1001, i32 0)
%14 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%15 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%16 = tail call i32 @ok(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%18 = tail call i32 @ipdivert_create(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%19 = tail call i32 @ipdivert_bind(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 1000, i32 0)
%20 = load i32, i32* @EADDRINUSE
%21 = tail call i32 @ipdivert_bind(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %18, i32 1000, i32 %20)
%22 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%23 = tail call i32 @ipdivert_close(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%24 = tail call i32 @ok(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}