#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 /*<<< orphan*/ EX_OSERR;
size_t confstr(int, char *, size_t);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
int errno;
int /*<<< orphan*/ printf(char *, ...);
void do_confstr(const char *name, int key) {
  size_t len;
  int savederr;
  savederr = errno;
  errno = 0;
  len = confstr(key, 0, 0);
  if (len == 0) {
    if (errno)
      err(EX_OSERR, "confstr: %s", name);
    else
      printf("undefined\n");
  } else {
    char buf[len + 1];
    confstr(key, buf, len);
    printf("%s\n", buf);
  }
  errno = savederr;
}


x86 assembly (clang, -O0):
<do_confstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e8e(%rip),%rax
movl   $0x0,(%rax)
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <confstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b7 <do_confstr+0x87>
mov    0x2e63(%rip),%rax
cmpl   $0x0,(%rax)
je     11a4 <do_confstr+0x74>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe66(%rip),%rsi
call   1040 <err@plt>
jmp    11b2 <do_confstr+0x82>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1207 <do_confstr+0xd7>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rdx
call   1050 <confstr@plt>
mov    -0x38(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x1c(%rbp),%ecx
mov    0x2dcf(%rip),%rax
mov    %ecx,(%rax)
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_confstr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2e95(%rip),%r12
mov    (%r12),%r13d
movl   $0x0,(%r12)
mov    %esi,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <confstr@plt>
test   %rax,%rax
je     1199 <do_confstr+0x69>
mov    %rsp,%r14
mov    %rsp,%rbx
mov    %rax,%rcx
add    $0x10,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <confstr@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %r14,%rsp
jmp    11c6 <do_confstr+0x96>
cmpl   $0x0,(%r12)
je     11ba <do_confstr+0x8a>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
mov    %r14,%rdx
call   1040 <err@plt>
jmp    11c6 <do_confstr+0x96>
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    %r13d,(%r12)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EX_OSERR = global i32 0
@.str = [12 x i8] c"confstr: %s\00"
@.str.1 = [11 x i8] c"undefined\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @do_confstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @errno
store i32 %9, i32* %6
store i32 0, i32* @errno
%10 = load i32, i32* %4
%11 = call i64 @confstr(i32 %10, i8* null, i64 0)
store i64 %11, i64* %5
%12 = load i64, i64* %5
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* @EX_OSERR
%19 = load i8*, i8** %3
%20 = call i32 @err(i32 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
br label %34
24: ; preds = %2
%25 = load i64, i64* %5
%26 = add i64 %25, 1
%27 = call i8* @llvm.stacksave()
store i8* %27, i8** %7
%28 = alloca i8, i64 %26
store i64 %26, i64* %8
%29 = load i32, i32* %4
%30 = load i64, i64* %5
%31 = call i64 @confstr(i32 %29, i8* %28, i64 %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%33 = load i8*, i8** %7
br label %34
34: ; preds = %24, %23
%35 = load i32, i32* %6
store i32 %35, i32* @errno
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@EX_OSERR = global i32 0
@.str = [12 x i8] c"confstr: %s\00"
@str = [10 x i8] c"undefined\00"
define void @do_confstr(i8* %0, i32 %1) {
%3 = load i32, i32* @errno
store i32 0, i32* @errno
%4 = tail call i64 @confstr(i32 %1, i8* null, i64 0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %2
%7 = load i32, i32* @errno
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i32, i32* @EX_OSERR
%11 = tail call i32 @err(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %20
14: ; preds = %2
%15 = add i64 %4, 1
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = call i64 @confstr(i32 %1, i8* %17, i64 %4)
%19 = call i32 @puts(i8* %17)
br label %20
20: ; preds = %9, %12, %14
store i32 %3, i32* @errno
ret void
}