#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(void) {
  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    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
lea    0xe45(%rip),%rsi
call   1080 <strlcpy@plt>
mov    -0x28(%rbp),%rdi
call   1090 <mkdtemp@plt>
cmp    $0x0,%rax
jne    11e4 <main+0x74>
mov    $0xffffffff,%edi
lea    0xe38(%rip),%rsi
call   1070 <err@plt>
mov    -0x28(%rbp),%rdi
call   1050 <push_path@plt>
mov    -0x28(%rbp),%rdi
call   1060 <bind_test@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    120f <main+0x9f>
mov    -0x28(%rbp),%rdi
call   1040 <connect_test@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <unwind@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%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() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %2
%8 = alloca i8, i64 %6
store i64 %6, i64* %3
%9 = load i32, i32* @PATH_MAX
%10 = call i32 @strlcpy(i8* %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32* @mkdtemp(i8* %8)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @err(i32 -1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = call i32 @push_path(i8* %8)
%17 = call i32 @bind_test(i8* %8)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @connect_test(i8* %8)
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %15
%23 = call i32 (...) @unwind()
%24 = load i32, i32* %4
store i32 %24, i32* %1
%25 = load i8*, i8** %2
%26 = load i32, i32* %1
ret i32 %26
}

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() {
%1 = load i32, i32* @PATH_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i32 @strlcpy(i8* %3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = call i32* @mkdtemp(i8* %3)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @err(i32 -1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @push_path(i8* %3)
%11 = call i32 @bind_test(i8* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @connect_test(i8* %3)
br label %15
15: ; preds = %13, %9
%16 = phi i32 [ %14, %13 ], [ %11, %9 ]
%17 = call i32 (...) @unwind()
ret i32 %16
}