#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 stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISSOCK(int /*<<< orphan*/);
char *get_temp_directory();
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int);
scalar_t__ stat(char *, struct stat *);
int check_socket(int pid) {
  char path[1024];
  snprintf(path, 1024, "%s/.java_pid%d", get_temp_directory(), pid);
  struct stat stats;
  return stat(path, &stats) == 0 && S_ISSOCK(stats.st_mode);
}


x86 assembly (clang, -O0):
<check_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    $0x0,%al
call   1060 <get_temp_directory@plt>
mov    -0x428(%rbp),%rdi
mov    %rax,%rcx
mov    -0x4(%rbp),%r8d
mov    $0x400,%esi
lea    0xe83(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1050 <stat@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x419(%rbp)
jne    11c2 <check_socket+0x82>
mov    -0x418(%rbp),%edi
call   1030 <S_ISSOCK@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x419(%rbp)
mov    -0x419(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_socket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <get_temp_directory@plt>
lea    0xea3(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rax,%rcx
mov    %ebp,%r8d
call   1040 <snprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
test   %rax,%rax
jne    1198 <check_socket+0x58>
mov    0x8(%rsp),%edi
call   1030 <S_ISSOCK@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"%s/.java_pid%d\00"
define i32 @check_socket(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
store i32 %0, i32* %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i8* (...) @get_temp_directory()
%7 = load i32, i32* %2
%8 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %6, i32 %7)
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i64 @stat(i8* %9, %struct.stat* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISSOCK(i32 %14)
%16 = icmp ne i64 %15, 0
br label %17
17: ; preds = %12, %1
%18 = phi i1 [ false, %1 ], [ %16, %12 ]
%19 = zext i1 %18 to i32
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"%s/.java_pid%d\00"
define i32 @check_socket(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca %struct.stat
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i8* (...) @get_temp_directory()
%6 = call i32 @snprintf(i8* %4, i32 1024, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5, i32 %0)
%7 = bitcast %struct.stat* %3 to i8*
%8 = call i64 @stat(i8* %4, %struct.stat* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @S_ISSOCK(i32 %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %10, %1
%17 = phi i32 [ 0, %1 ], [ %15, %10 ]
ret i32 %17
}