#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 AF_INET;
int AF_UNIX;
char *getenv(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int parseSocketVariable(char *buffer, int bufferSize) {
  char *env;
  env = getenv("RTPROF_SKT");
  if (env != NULL) {
    if (!strncmp(env, "rtprof://", 9)) {
      strncpy(buffer, env + 9, bufferSize - 9);
      return AF_INET;
    } else if (!strncmp(env, "unix://", 7)) {
      strncpy(buffer, env + 7, bufferSize - 7);
      return AF_UNIX;
    } else
      return -1;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<parseSocketVariable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f2 <parseSocketVariable+0xc2>
mov    -0x20(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x9,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    11a0 <parseSocketVariable+0x70>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x9,%rsi
mov    -0x14(%rbp),%edx
sub    $0x9,%edx
call   1040 <strncpy@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <parseSocketVariable+0xc9>
mov    -0x20(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x7,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    11e6 <parseSocketVariable+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x7,%rsi
mov    -0x14(%rbp),%edx
sub    $0x7,%edx
call   1040 <strncpy@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f9 <parseSocketVariable+0xc9>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <parseSocketVariable+0xc9>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseSocketVariable>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xebc(%rip),%rdi
call   1030 <getenv@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11be <parseSocketVariable+0x8e>
mov    %rax,%rbx
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
mov    $0x9,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
je     1199 <parseSocketVariable+0x69>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
jne    11be <parseSocketVariable+0x8e>
mov    0x2e53(%rip),%rbp
mov    $0xfffffff9,%edx
mov    $0x7,%eax
jmp    11aa <parseSocketVariable+0x7a>
mov    0x2e48(%rip),%rbp
mov    $0xfffffff7,%edx
mov    $0x9,%eax
add    %rax,%rbx
add    %r15d,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strncpy@plt>
mov    0x0(%rbp),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"RTPROF_SKT\00"
@.str.1 = [10 x i8] c"rtprof://\00"
@AF_INET = global i32 0
@.str.2 = [8 x i8] c"unix://\00"
@AF_UNIX = global i32 0
define i32 @parseSocketVariable(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %35
10: ; preds = %2
%11 = load i8*, i8** %6
%12 = call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%13 = icmp ne i32 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8*, i8** %6
%17 = getelementptr inbounds i8, i8* %16, i64 9
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, 9
%20 = call i32 @strncpy(i8* %15, i8* %17, i32 %19)
%21 = load i32, i32* @AF_INET
store i32 %21, i32* %3
br label %36
22: ; preds = %10
%23 = load i8*, i8** %6
%24 = call i32 @strncmp(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%25 = icmp ne i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load i8*, i8** %6
%29 = getelementptr inbounds i8, i8* %28, i64 7
%30 = load i32, i32* %5
%31 = sub nsw i32 %30, 7
%32 = call i32 @strncpy(i8* %27, i8* %29, i32 %31)
%33 = load i32, i32* @AF_UNIX
store i32 %33, i32* %3
br label %36
34: ; preds = %22
store i32 -1, i32* %3
br label %36
35: ; preds = %2
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %34, %26, %14
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [11 x i8] c"RTPROF_SKT\00"
@.str.1 = [10 x i8] c"rtprof://\00"
@AF_INET = global i32 0
@.str.2 = [8 x i8] c"unix://\00"
@AF_UNIX = global i32 0
define i32 @parseSocketVariable(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = tail call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 9)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @strncmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 7)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8, %5
%12 = phi i64 [ 9, %5 ], [ 7, %8 ]
%13 = phi i32 [ -9, %5 ], [ -7, %8 ]
%14 = phi i32* [ @AF_INET, %5 ], [ @AF_UNIX, %8 ]
%15 = getelementptr inbounds i8, i8* %3, i64 %12
%16 = add nsw i32 %13, %1
%17 = tail call i32 @strncpy(i8* %0, i8* %15, i32 %16)
%18 = load i32, i32* %14
br label %19
19: ; preds = %11, %2, %8
%20 = phi i32 [ -1, %8 ], [ -1, %2 ], [ %18, %11 ]
ret i32 %20
}