#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ perror(char *);
char *strchr(char *, char);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ *strstr(char *, char const *);
char *app_macconf_item_get(char **item_pointer, const char *item_name) {
  char line[81];
  FILE *cf = NULL;
  int len = 0;
  cf = fopen("/etc/mac.conf", "r");
  if (cf == NULL) {
    perror("/etc/mac.conf");
    return NULL;
  }
  while ((fgets(line, 81, cf)) != NULL) {
    if (strstr(line, item_name) != NULL) {
      len = strlen(line);
      break;
    }
  }
  fclose(cf);
  if (len == 0)
    return NULL;
  if (line[len - 1] == '\n')
    line[len - 1] = '\0';
  if (*item_pointer != NULL)
    free(*item_pointer);
  if (strchr(line, '=') != NULL) {
    *item_pointer = strdup(strchr(line, '=') + 1);
  } else {
    *item_pointer = strdup(line);
  }
  assert(*item_pointer != NULL);
  return *item_pointer;
}


x86 assembly (clang, -O0):
<app_macconf_item_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
lea    0xe37(%rip),%rdi
lea    0xe3e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    11fd <app_macconf_item_get+0x5d>
lea    0xe15(%rip),%rdi
call   10a0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    131c <app_macconf_item_get+0x17c>
jmp    1202 <app_macconf_item_get+0x62>
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rdx
mov    $0x51,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     124b <app_macconf_item_get+0xab>
lea    -0x70(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     1246 <app_macconf_item_get+0xa6>
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x7c(%rbp)
jmp    124b <app_macconf_item_get+0xab>
jmp    1202 <app_macconf_item_get+0x62>
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x7c(%rbp)
jne    126b <app_macconf_item_get+0xcb>
movq   $0x0,-0x8(%rbp)
jmp    131c <app_macconf_item_get+0x17c>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    128e <app_macconf_item_get+0xee>
mov    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     12a8 <app_macconf_item_get+0x108>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
lea    -0x70(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     12e9 <app_macconf_item_get+0x149>
lea    -0x70(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    12fc <app_macconf_item_get+0x15c>
lea    -0x70(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<app_macconf_item_get>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe48(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1284 <app_macconf_item_get+0xe4>
mov    %rax,%r12
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x51,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     126e <app_macconf_item_get+0xce>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     11e0 <app_macconf_item_get+0x40>
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %ebx,%ebx
je     1276 <app_macconf_item_get+0xd6>
movslq %ebx,%rax
cmpb   $0xa,-0x1(%rax,%r15,1)
jne    122e <app_macconf_item_get+0x8e>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    (%r14),%rdi
test   %rdi,%rdi
je     123b <app_macconf_item_get+0x9b>
call   1030 <free@plt>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
lea    0x1(%rax),%rdi
test   %rax,%rax
cmove  %r15,%rdi
call   10b0 <strdup@plt>
mov    %rax,(%r14)
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1080 <assert@plt>
mov    (%r14),%rax
jmp    1278 <app_macconf_item_get+0xd8>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd75(%rip),%rdi
call   10a0 <perror@plt>
jmp    1276 <app_macconf_item_get+0xd6>

LLVM IR (-O0):
@.str = [14 x i8] c"/etc/mac.conf\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @app_macconf_item_get(i8** %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca [81 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i32* null, i32** %7
store i32 0, i32* %8
%9 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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** %7
%10 = load i32*, i32** %7
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %3
br label %78
14: ; preds = %2
br label %15
15: ; preds = %28, %14
%16 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%17 = load i32*, i32** %7
%18 = call i32* @fgets(i8* %16, i32 81, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = call i32* @strstr(i8* %21, i8* %22)
%24 = icmp ne i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %8
br label %29
28: ; preds = %20
br label %15
29: ; preds = %25, %15
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
store i8* null, i8** %3
br label %78
35: ; preds = %29
%36 = load i32, i32* %8
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %48
43: ; preds = %35
%44 = load i32, i32* %8
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %43, %35
%49 = load i8**, i8*** %4
%50 = load i8*, i8** %49
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i8**, i8*** %4
%54 = load i8*, i8** %53
%55 = call i32 @free(i8* %54)
br label %56
56: ; preds = %52, %48
%57 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%58 = call i8* @strchr(i8* %57, i8 signext 61)
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%62 = call i8* @strchr(i8* %61, i8 signext 61)
%63 = getelementptr inbounds i8, i8* %62, i64 1
%64 = call i8* @strdup(i8* %63)
%65 = load i8**, i8*** %4
store i8* %64, i8** %65
br label %70
66: ; preds = %56
%67 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%68 = call i8* @strdup(i8* %67)
%69 = load i8**, i8*** %4
store i8* %68, i8** %69
br label %70
70: ; preds = %66, %60
%71 = load i8**, i8*** %4
%72 = load i8*, i8** %71
%73 = icmp ne i8* %72, null
%74 = zext i1 %73 to i32
%75 = call i32 @assert(i32 %74)
%76 = load i8**, i8*** %4
%77 = load i8*, i8** %76
store i8* %77, i8** %3
br label %78
78: ; preds = %70, %34, %12
%79 = load i8*, i8** %3
ret i8* %79
}

LLVM IR (-O2):
@.str = [14 x i8] c"/etc/mac.conf\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @app_macconf_item_get(i8** nocapture %0, i8* nocapture %1) {
%3 = alloca [81 x i8]
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %43
9: ; preds = %2, %14
%10 = call i32* @fgets(i8* %4, i32 81, i32* %5)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = call i32 @fclose(i32* %5)
br label %43
14: ; preds = %9
%15 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %1)
%16 = icmp eq i32* %15, null
br i1 %16, label %9, label %17
17: ; preds = %14
%18 = call i32 @strlen(i8* %4)
%19 = call i32 @fclose(i32* %5)
%20 = icmp eq i32 %18, 0
br i1 %20, label %43, label %21
21: ; preds = %17
%22 = add nsw i32 %18, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %21
store i8 0, i8* %24
br label %28
28: ; preds = %27, %21
%29 = load i8*, i8** %0
%30 = icmp eq i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %28
%32 = call i32 @free(i8* %29)
br label %33
33: ; preds = %31, %28
%34 = call i8* @strchr(i8* %4, i8 signext 61)
%35 = icmp eq i8* %34, null
%36 = getelementptr inbounds i8, i8* %34, i64 1
%37 = select i1 %35, i8* %4, i8* %36
%38 = call i8* @strdup(i8* %37)
store i8* %38, i8** %0
%39 = icmp ne i8* %38, null
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i8*, i8** %0
br label %43
43: ; preds = %12, %17, %33, %7
%44 = phi i8* [ null, %7 ], [ %42, %33 ], [ null, %17 ], [ null, %12 ]
ret i8* %44
}