#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 */
struct sockaddr_un {
  char *sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef scalar_t__ socklen_t;
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ PF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, scalar_t__);
scalar_t__ chmod(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int main(int argc, char **argv) {
  int fd;
  struct sockaddr_un sa;
  socklen_t salen;
  char log_path[255];
  printf("tsock - starting\n");
  if (argc > 1) {
    strcpy(log_path, argv[1]);
  } else {
    strcpy(log_path, "./log-socket");
  }
  printf("log_path = \"%s\"\n", log_path);
  unlink(log_path);
  fd = socket(PF_UNIX, SOCK_DGRAM, 0);
  if (fd < 0) {
    fprintf(stderr, "socket() call failed - exiting.\n");
    exit(1);
  }
  memset(&sa, 0, sizeof(sa));
  sa.sun_family = PF_UNIX;
  strcpy(sa.sun_path, log_path);
  salen = sizeof(sa.sun_family) + strlen(sa.sun_path);
  if (bind(fd, (struct sockaddr *)&sa, salen) < 0) {
    fprintf(stderr, "bind() call failed - exiting.\n");
    exit(1);
  }
  if (chmod(log_path, 0666) < 0) {
    fprintf(stderr, "chmod() call failed - exiting.\n");
    exit(1);
  }
  printf("tsock - start-up successful, ...\n");
  sleep(10);
  unlink(log_path);
  printf("exiting.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11fa <main+0x4a>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    120d <main+0x5d>
lea    -0x130(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x130(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x130(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1273 <main+0xc3>
mov    0x2d75(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   10a0 <bind@plt>
cmp    $0x0,%rax
jge    12e9 <main+0x139>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
lea    0xd77(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x130(%rbp),%rdi
mov    $0x1b6,%esi
call   1090 <chmod@plt>
cmp    $0x0,%rax
jge    1323 <main+0x173>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   10c0 <sleep@plt>
lea    -0x130(%rbp),%rdi
call   1030 <unlink@plt>
lea    0xd18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea7(%rip),%rdi
call   1050 <puts@plt>
cmp    $0x2,%ebp
jl     11e7 <main+0x27>
mov    0x8(%rbx),%rsi
jmp    11ee <main+0x2e>
lea    0xe12(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    0x2ddd(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     12c9 <main+0x109>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    (%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1040 <strcpy@plt>
mov    (%rsp),%rdi
call   1060 <strlen@plt>
lea    0x4(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   10b0 <bind@plt>
test   %rax,%rax
js     12db <main+0x11b>
lea    0x10(%rsp),%rdi
mov    $0x1b6,%esi
call   10a0 <chmod@plt>
test   %rax,%rax
js     12ed <main+0x12d>
lea    0xdf9(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   10d0 <sleep@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
lea    0xdfa(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
lea    0xd45(%rip),%rsi
jmp    12fd <main+0x13d>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
jmp    12fd <main+0x13d>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str = [18 x i8] c"tsock - starting\0A\00"
@.str.1 = [13 x i8] c"./log-socket\00"
@.str.2 = [17 x i8] c"log_path = \22%s\22\0A\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"socket() call failed - exiting.\0A\00"
@.str.4 = [31 x i8] c"bind() call failed - exiting.\0A\00"
@.str.5 = [32 x i8] c"chmod() call failed - exiting.\0A\00"
@.str.6 = [34 x i8] c"tsock - start-up successful, ...\0A\00"
@.str.7 = [10 x i8] c"exiting.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_un
%8 = alloca i64
%9 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %14, i8* %17)
br label %22
19: ; preds = %2
%20 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %19, %13
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%26 = call i32 @unlink(i8* %25)
%27 = load i32, i32* @PF_UNIX
%28 = load i32, i32* @SOCK_DGRAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %22
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %22
%37 = call i32 @memset(%struct.sockaddr_un* %7, i32 0, i32 16)
%38 = load i32, i32* @PF_UNIX
%39 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %7, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i64 @strlen(i8* %45)
%47 = add i64 4, %46
store i64 %47, i64* %8
%48 = load i32, i32* %6
%49 = bitcast %struct.sockaddr_un* %7 to %struct.sockaddr*
%50 = load i64, i64* %8
%51 = call i64 @bind(i32 %48, %struct.sockaddr* %49, i64 %50)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %36
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %36
%58 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%59 = call i64 @chmod(i8* %58, i32 438)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %57
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %57
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
%67 = call i32 @sleep(i32 10)
%68 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%69 = call i32 @unlink(i8* %68)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i8*, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [13 x i8] c"./log-socket\00"
@.str.2 = [17 x i8] c"log_path = \22%s\22\0A\00"
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"socket() call failed - exiting.\0A\00"
@.str.4 = [31 x i8] c"bind() call failed - exiting.\0A\00"
@.str.5 = [32 x i8] c"chmod() call failed - exiting.\0A\00"
@str = [17 x i8] c"tsock - starting\00"
@str.8 = [33 x i8] c"tsock - start-up successful, ...\00"
@str.9 = [9 x i8] c"exiting.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_un
%4 = alloca [255 x i8]
%5 = bitcast %struct.sockaddr_un* %3 to i8*
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
br label %12
12: ; preds = %2, %9
%13 = phi i8* [ %11, %9 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %2 ]
%14 = call i32 @strcpy(i8* %6, i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%16 = call i32 @unlink(i8* %6)
%17 = load i32, i32* @PF_UNIX
%18 = load i32, i32* @SOCK_DGRAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %12
%26 = call i32 @memset(%struct.sockaddr_un* %3, i32 0, i32 16)
%27 = load i32, i32* @PF_UNIX
%28 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 1
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %3, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %30, i8* %6)
%32 = load i8*, i8** %29
%33 = call i64 @strlen(i8* dereferenceable(1) %32)
%34 = add i64 %33, 4
%35 = bitcast %struct.sockaddr_un* %3 to %struct.sockaddr*
%36 = call i64 @bind(i32 %19, %struct.sockaddr* %35, i64 %34)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %25
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %25
%43 = call i64 @chmod(i8* %6, i32 438)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %42
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
%51 = call i32 @sleep(i32 10)
%52 = call i32 @unlink(i8* %6)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.9, i64 0, i64 0))
ret i32 0
}