#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *getenv(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ sscanf(char *, char *, char *);
char *strdup(char *);
char *getsetting(char *setting) {
  FILE *f;
  char *s = NULL;
  char *home;
  char temp[1024];
  char sub[1024];
  char fmt[1024];
  home = getenv("HOME");
  sprintf(temp, "%s/.libufs", home);
  f = fopen(temp, "r");
  if (!f) {
    return s;
  }
  sprintf(fmt, "%s=%%s", setting);
  while (fgets(temp, 1024, f)) {
    bzero(sub, 800);
    if (sscanf(temp, fmt, sub)) {
      s = strdup(sub);
    }
  }
  fclose(f);
  return s;
}


x86 assembly (clang, -O0):
<getsetting>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe62(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ed <getsetting+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    127e <getsetting+0xfe>
lea    -0xc30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe13(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     126d <getsetting+0xed>
lea    -0x830(%rbp),%rdi
mov    $0x320,%esi
call   1080 <bzero@plt>
lea    -0x430(%rbp),%rdi
lea    -0xc30(%rbp),%rsi
lea    -0x830(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x0,%rax
je     1268 <getsetting+0xe8>
lea    -0x830(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    1204 <getsetting+0x84>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getsetting>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc00,%rsp
mov    %rdi,%r14
lea    0xe66(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe5f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1090 <sprintf@plt>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     126c <getsetting+0xec>
mov    %rax,%r15
lea    0xe3c(%rip),%rsi
lea    0x400(%rsp),%rdi
mov    %r14,%rdx
call   1090 <sprintf@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     1262 <getsetting+0xe2>
lea    0x800(%rsp),%rbx
mov    %rsp,%r12
lea    0x400(%rsp),%r13
jmp    1235 <getsetting+0xb5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1262 <getsetting+0xe2>
mov    %rbx,%rdi
mov    $0x320,%esi
call   1080 <bzero@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <sscanf@plt>
test   %rax,%rax
je     1220 <getsetting+0xa0>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r14
jmp    1220 <getsetting+0xa0>
mov    %r15,%rdi
call   1040 <fclose@plt>
jmp    126f <getsetting+0xef>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0xc00,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"%s/.libufs\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"%s=%%s\00"
define i8* @getsetting(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
store i8* %0, i8** %3
store i8* null, i8** %5
%10 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %6
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp ne i32* %16, null
br i1 %17, label %20, label %18
18: ; preds = %1
%19 = load i8*, i8** %5
store i8* %19, i8** %2
br label %45
20: ; preds = %1
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %3
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %40, %20
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i32*, i32** %4
%27 = call i64 @fgets(i8* %25, i32 1024, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %41
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%31 = call i32 @bzero(i8* %30, i32 800)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = call i64 @sscanf(i8* %32, i8* %33, i8* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %29
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = call i8* @strdup(i8* %38)
store i8* %39, i8** %5
br label %40
40: ; preds = %37, %29
br label %24
41: ; preds = %24
%42 = load i32*, i32** %4
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %5
store i8* %44, i8** %2
br label %45
45: ; preds = %41, %18
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@.str.1 = [11 x i8] c"%s/.libufs\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [7 x i8] c"%s=%%s\00"
define noalias i8* @getsetting(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %30, label %12
12: ; preds = %1
%13 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%14 = call i64 @fgets(i8* %5, i32 1024, i32* %10)
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %12, %23
%17 = phi i8* [ %24, %23 ], [ null, %12 ]
%18 = call i32 @bzero(i8* %6, i32 800)
%19 = call i64 @sscanf(i8* %5, i8* %7, i8* %6)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %16
%22 = call i8* @strdup(i8* %6)
br label %23
23: ; preds = %21, %16
%24 = phi i8* [ %22, %21 ], [ %17, %16 ]
%25 = call i64 @fgets(i8* %5, i32 1024, i32* %10)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %16
27: ; preds = %23, %12
%28 = phi i8* [ null, %12 ], [ %24, %23 ]
%29 = call i32 @fclose(i32* %10)
br label %30
30: ; preds = %1, %27
%31 = phi i8* [ %28, %27 ], [ null, %1 ]
ret i8* %31
}