#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *);
char *malloc(int);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *get_config(char *name) {
  char *value = malloc(1024);
  FILE *configfile = fopen("config.txt", "r");
  value[0] = '\0';
  if (configfile != NULL) {
    while (1) {
      char configname[1024];
      char tempvalue[1024];
      int status =
          fscanf(configfile, " %1023[^= ] = %s ", configname, tempvalue);
      if (status == EOF) {
        break;
      }
      if (strcmp(configname, name) == 0) {
        strncpy(value, tempvalue, strlen(tempvalue) + 1);
        break;
      }
    }
    fclose(configfile);
  }
  return value;
}


x86 assembly (clang, -O0):
<get_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe6c(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1265 <get_config+0xf5>
jmp    11bb <get_config+0x4b>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    -0x820(%rbp),%rcx
lea    0xe39(%rip),%rsi
call   1060 <fscanf@plt>
mov    %eax,-0x824(%rbp)
mov    -0x824(%rbp),%eax
mov    0x2dfc(%rip),%rcx
cmp    (%rcx),%eax
jne    11f9 <get_config+0x89>
jmp    125c <get_config+0xec>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1257 <get_config+0xe7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x820(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x820(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x838(%rbp),%rdi
mov    -0x830(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
jmp    125c <get_config+0xec>
jmp    11bb <get_config+0x4b>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_config>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%r15
mov    $0x400,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe68(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
movb   $0x0,(%rbx)
test   %rax,%rax
je     1253 <get_config+0xe3>
mov    %rax,%r12
mov    %rbx,0x8(%rsp)
lea    0xe4e(%rip),%rsi
lea    0x410(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    0x2e0d(%rip),%r14
cmp    (%r14),%eax
je     1246 <get_config+0xd6>
lea    0x410(%rsp),%rbx
lea    0xe1e(%rip),%r13
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1228 <get_config+0xb8>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
call   1060 <fscanf@plt>
cmp    (%r14),%eax
jne    1200 <get_config+0x90>
jmp    1246 <get_config+0xd6>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"config.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c" %1023[^= ] = %s \00"
@EOF = global i32 0
define i8* @get_config(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i8* @malloc(i32 1024)
store i8* %8, i8** %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 0, i8* %11
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %40
14: ; preds = %1
br label %15
15: ; preds = %14, %36
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %18)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
br label %37
24: ; preds = %15
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%26 = load i8*, i8** %2
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i64 @strlen(i8* %32)
%34 = add nsw i64 %33, 1
%35 = call i32 @strncpy(i8* %30, i8* %31, i64 %34)
br label %37
36: ; preds = %24
br label %15
37: ; preds = %29, %23
%38 = load i32*, i32** %4
%39 = call i32 @fclose(i32* %38)
br label %40
40: ; preds = %37, %1
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@.str = [11 x i8] c"config.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [18 x i8] c" %1023[^= ] = %s \00"
@EOF = global i32 0
define i8* @get_config(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* %4
%6 = icmp eq i32* %5, null
br i1 %6, label %26, label %7
7: ; preds = %1
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %24, label %13
13: ; preds = %7, %20
%14 = call i64 @strcmp(i8* %8, i8* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = call i64 @strlen(i8* %9)
%18 = add nsw i64 %17, 1
%19 = call i32 @strncpy(i8* %4, i8* %9, i64 %18)
br label %24
20: ; preds = %13
%21 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %9)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %13
24: ; preds = %20, %7, %16
%25 = call i32 @fclose(i32* %5)
br label %26
26: ; preds = %24, %1
ret i8* %4
}