#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 */
char *getenv(char const *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *get_socket_env(const char *name) {
  char *value = getenv(name);
  if (value == NULL)
    return NULL;
  if (strncmp(value, "unix:path=", strlen("unix:path=")) == 0)
    return value + strlen("unix:path=");
  return NULL;
}


x86 assembly (clang, -O0):
<get_socket_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <get_socket_env+0x31>
movq   $0x0,-0x8(%rbp)
jmp    11c2 <get_socket_env+0x92>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe90(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe7e(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    11ba <get_socket_env+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe60(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <get_socket_env+0x92>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_socket_env>:
push   %r14
push   %rbx
push   %rax
call   1030 <getenv@plt>
test   %rax,%rax
je     1162 <get_socket_env+0x32>
mov    %rax,%rbx
lea    0xeb8(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     1166 <get_socket_env+0x36>
xor    %ebx,%ebx
jmp    1177 <get_socket_env+0x47>
lea    0xe93(%rip),%rdi
call   1050 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [11 x i8] c"unix:path=\00"
define i8* @get_socket_env(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @getenv(i8* %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %21
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%13 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8* %19, i8** %2
br label %21
20: ; preds = %10
store i8* null, i8** %2
br label %21
21: ; preds = %20, %15, %9
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [11 x i8] c"unix:path=\00"
define i8* @get_socket_env(i8* nocapture %0) {
%2 = tail call i8* @getenv(i8* %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%6 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
br label %12
12: ; preds = %4, %1, %8
%13 = phi i8* [ %11, %8 ], [ null, %1 ], [ null, %4 ]
ret i8* %13
}