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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int read_config(char *name, char *key, char *value) {
  FILE *file = fopen(name, "r");
  if (file == NULL) {
    return 0;
  }
  char buffer[100];
  char delims[] = " \t\n";
  char *temp;
  while (fgets(buffer, sizeof(buffer), file) != NULL) {
    temp = strtok(buffer, delims);
    if (temp != NULL && strcmp(temp, key) == 0) {
      if ((temp = strtok(NULL, delims)) != NULL) {
        strcpy(value, temp);
      }
      break;
    }
  }
  fclose(file);
  return 1;
}


x86 assembly (clang, -O0):
<read_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a2 <read_config+0x42>
movl   $0x0,-0x4(%rbp)
jmp    125a <read_config+0xfa>
mov    0xe5a(%rip),%eax
mov    %eax,-0x94(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     124a <read_config+0xea>
lea    -0x90(%rbp),%rdi
lea    -0x94(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
je     1245 <read_config+0xe5>
mov    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1245 <read_config+0xe5>
lea    -0x94(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
je     1240 <read_config+0xe0>
mov    -0x20(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    124a <read_config+0xea>
jmp    11ae <read_config+0x4e>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_config>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1220 <read_config+0xc0>
mov    %rax,%r12
movl   $0xa0920,0xc(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1211 <read_config+0xb1>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r13
jmp    11d5 <read_config+0x75>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1211 <read_config+0xb1>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11c0 <read_config+0x60>
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11c0 <read_config+0x60>
lea    0xc(%rsp),%rsi
xor    %edi,%edi
call   1080 <strtok@plt>
test   %rax,%rax
je     1211 <read_config+0xb1>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    $0x1,%eax
jmp    1222 <read_config+0xc2>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@__const.read_config.delims = [4 x i8] c" \09\0A\00"
define i32 @read_config(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca [100 x i8]
%10 = alloca [4 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %48
17: ; preds = %3
%18 = bitcast [4 x i8]* %10 to i8*
br label %19
19: ; preds = %44, %17
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%21 = load i32*, i32** %8
%22 = call i32* @fgets(i8* %20, i32 100, i32* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %45
24: ; preds = %19
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%27 = call i8* @strtok(i8* %25, i8* %26)
store i8* %27, i8** %11
%28 = load i8*, i8** %11
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %44
30: ; preds = %24
%31 = load i8*, i8** %11
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i8* %31, i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = getelementptr inbounds [4 x i8], [4 x i8]* %10, i64 0, i64 0
%37 = call i8* @strtok(i8* null, i8* %36)
store i8* %37, i8** %11
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %43
39: ; preds = %35
%40 = load i8*, i8** %7
%41 = load i8*, i8** %11
%42 = call i32 @strcpy(i8* %40, i8* %41)
br label %43
43: ; preds = %39, %35
br label %45
44: ; preds = %30, %24
br label %19
45: ; preds = %43, %19
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
store i32 1, i32* %4
br label %48
48: ; preds = %45, %16
%49 = load i32, i32* %4
ret i32 %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @read_config(i8* nocapture %0, i8* %1, i8* %2) {
%4 = alloca [100 x i8]
%5 = alloca i32
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %3
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
store i32 657696, i32* %5
%11 = call i32* @fgets(i8* %9, i32 100, i32* %6)
%12 = icmp eq i32* %11, null
br i1 %12, label %27, label %13
13: ; preds = %8, %24
%14 = call i8* @strtok(i8* %9, i8* %10)
%15 = icmp eq i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = call i64 @strcmp(i8* %14, i8* %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = call i8* @strtok(i8* null, i8* %10)
%21 = icmp eq i8* %20, null
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i32 @strcpy(i8* %2, i8* %20)
br label %27
24: ; preds = %16, %13
%25 = call i32* @fgets(i8* %9, i32 100, i32* %6)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %13
27: ; preds = %24, %8, %19, %22
%28 = call i32 @fclose(i32* %6)
br label %29
29: ; preds = %3, %27
%30 = phi i32 [ 1, %27 ], [ 0, %3 ]
ret i32 %30
}