#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 */
typedef int /*<<< orphan*/ cs_path;

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
#define _CS_PATH 128
int /*<<< orphan*/ __set_errno(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t confstr(int name, char *buf, size_t len) {
  const char *string;
  size_t string_len;
  switch (name) {
  case _CS_PATH: {
    static const char cs_path[] = "/bin:/usr/bin";
    string = cs_path;
    string_len = sizeof(cs_path);
  } break;
  default:
    __set_errno(EINVAL);
    return 0;
  }
  if (len > 0 && buf != NULL) {
    if (string_len <= len)
      memcpy(buf, string, string_len);
    else {
      memcpy(buf, string, len - 1);
      buf[len - 1] = '\0';
    }
  }
  return string_len;
}


x86 assembly (clang, -O0):
<confstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
jne    115e <confstr+0x3e>
jmp    1146 <confstr+0x26>
lea    0xeb3(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0xe,-0x30(%rbp)
jmp    1179 <confstr+0x59>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <confstr+0xc5>
cmpq   $0x0,-0x20(%rbp)
jbe    11dd <confstr+0xbd>
cmpq   $0x0,-0x18(%rbp)
je     11dd <confstr+0xbd>
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
ja     11b3 <confstr+0x93>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <memcpy@plt>
jmp    11d8 <confstr+0xb8>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
sub    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11dd <confstr+0xbd>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<confstr>:
push   %r15
push   %r14
push   %rbx
cmp    $0x80,%edi
jne    1165 <confstr+0x45>
mov    %rsi,%r14
mov    $0xe,%r15d
test   %rsi,%rsi
je     1176 <confstr+0x56>
mov    %rdx,%rbx
test   %rdx,%rdx
je     1176 <confstr+0x56>
cmp    $0xe,%rbx
jb     117f <confstr+0x5f>
lea    0xeb0(%rip),%rsi
mov    $0xe,%r15d
mov    $0xe,%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
jmp    1176 <confstr+0x56>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1030 <__set_errno@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    -0x1(%rbx),%rdx
lea    0xe76(%rip),%rsi
mov    %r14,%rdi
call   1040 <memcpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
jmp    1176 <confstr+0x56>

LLVM IR (-O0):
@confstr.cs_path = internal constant [14 x i8] c"/bin:/usr/bin\00"
@EINVAL = global i32 0
define i64 @confstr(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i32, i32* %5
switch i32 %10, label %12 [
i32 128, label %11
]
11: ; preds = %3
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @confstr.cs_path, i64 0, i64 0), i8** %8
store i64 14, i64* %9
br label %15
12: ; preds = %3
%13 = load i32, i32* @EINVAL
%14 = call i32 @__set_errno(i32 %13)
store i64 0, i64* %4
br label %43
15: ; preds = %11
%16 = load i64, i64* %7
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %41
21: ; preds = %18
%22 = load i64, i64* %9
%23 = load i64, i64* %7
%24 = icmp ule i64 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = load i64, i64* %9
%29 = call i32 @memcpy(i8* %26, i8* %27, i64 %28)
br label %40
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = load i8*, i8** %8
%33 = load i64, i64* %7
%34 = sub i64 %33, 1
%35 = call i32 @memcpy(i8* %31, i8* %32, i64 %34)
%36 = load i8*, i8** %6
%37 = load i64, i64* %7
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %30, %25
br label %41
41: ; preds = %40, %18, %15
%42 = load i64, i64* %9
store i64 %42, i64* %4
br label %43
43: ; preds = %41, %12
%44 = load i64, i64* %4
ret i64 %44
}

LLVM IR (-O2):
@confstr.cs_path = internal constant [14 x i8] c"/bin:/usr/bin\00"
@EINVAL = global i32 0
define i64 @confstr(i32 %0, i8* %1, i64 %2) {
%4 = icmp eq i32 %0, 128
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = icmp ne i64 %2, 0
%7 = icmp ne i8* %1, null
%8 = and i1 %7, %6
br i1 %8, label %12, label %20
9: ; preds = %3
%10 = load i32, i32* @EINVAL
%11 = tail call i32 @__set_errno(i32 %10)
br label %20
12: ; preds = %5
%13 = icmp ugt i64 %2, 13
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @confstr.cs_path, i64 0, i64 0), i64 14)
br label %20
16: ; preds = %12
%17 = add nsw i64 %2, -1
%18 = tail call i32 @memcpy(i8* %1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @confstr.cs_path, i64 0, i64 0), i64 %17)
%19 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 0, i8* %19
br label %20
20: ; preds = %5, %16, %14, %9
%21 = phi i64 [ 0, %9 ], [ 14, %14 ], [ 14, %16 ], [ 14, %5 ]
ret i64 %21
}