#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 PATH_MAX;
int bind_test(char *);
int connect_test(char *);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ *mkdtemp(char *);
int /*<<< orphan*/ push_path(char *);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int /*<<< orphan*/ unwind();
int main(int argc, char *argv[]) {
  char directory_path[PATH_MAX];
  int error;
  strlcpy(directory_path, "/tmp/unix_bind.XXXXXXX", PATH_MAX);
  if (mkdtemp(directory_path) == NULL)
    err(-1, "mkdtemp");
  push_path(directory_path);
  error = bind_test(directory_path);
  if (error == 0)
    error = connect_test(directory_path);
  unwind();
  return (error);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
lea    0xe3e(%rip),%rsi
call   1080 <strlcpy@plt>
mov    -0x30(%rbp),%rdi
call   1090 <mkdtemp@plt>
cmp    $0x0,%rax
jne    11eb <main+0x7b>
mov    $0xffffffff,%edi
lea    0xe31(%rip),%rsi
call   1070 <err@plt>
mov    -0x30(%rbp),%rdi
call   1050 <push_path@plt>
mov    -0x30(%rbp),%rdi
call   1060 <bind_test@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1216 <main+0xa6>
mov    -0x30(%rbp),%rdi
call   1040 <connect_test@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <unwind@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%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   %r14
push   %rbx
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strlcpy@plt>
mov    %rbx,%rdi
call   1090 <mkdtemp@plt>
test   %rax,%rax
jne    11c1 <main+0x51>
lea    0xe60(%rip),%rsi
mov    $0xffffffff,%edi
call   1070 <err@plt>
mov    %rbx,%rdi
call   1050 <push_path@plt>
mov    %rbx,%rdi
call   1060 <bind_test@plt>
mov    %eax,%r14d
test   %eax,%eax
jne    11e3 <main+0x73>
mov    %rbx,%rdi
call   1040 <connect_test@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <unwind@plt>
mov    %r14d,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/tmp/unix_bind.XXXXXXX\00"
@.str.1 = [8 x i8] c"mkdtemp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i32, i32* @PATH_MAX
%14 = call i32 @strlcpy(i8* %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32* @mkdtemp(i8* %12)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @err(i32 -1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = call i32 @push_path(i8* %12)
%21 = call i32 @bind_test(i8* %12)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @connect_test(i8* %12)
store i32 %25, i32* %8
br label %26
26: ; preds = %24, %19
%27 = call i32 (...) @unwind()
%28 = load i32, i32* %8
store i32 %28, i32* %3
%29 = load i8*, i8** %6
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [23 x i8] c"/tmp/unix_bind.XXXXXXX\00"
@.str.1 = [8 x i8] c"mkdtemp\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @strlcpy(i8* %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %3)
%7 = call i32* @mkdtemp(i8* %5)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @err(i32 -1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = call i32 @push_path(i8* %5)
%13 = call i32 @bind_test(i8* %5)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @connect_test(i8* %5)
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ %16, %15 ], [ %13, %11 ]
%19 = call i32 (...) @unwind()
ret i32 %18
}