#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, int *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int configReadID(char *filename, char *name) {
  FILE *file = fopen(filename, "r");
  char line[256];
  int id = -1;
  char read[256];
  if (file != NULL) {
    while (fgets(line, 255, file) != NULL) {
      sscanf(line, "%[a-zA-z0-9]:x:%i:\n", read, &id);
      if (!strncmp(read, name, 32)) {
        fclose(file);
        return id;
      }
    }
    fclose(file);
  }
  return -2;
}


x86 assembly (clang, -O0):
<configReadID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x124(%rbp)
ff ff ff
cmpq   $0x0,-0x20(%rbp)
je     1214 <configReadID+0xc4>
jmp    1191 <configReadID+0x41>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     120b <configReadID+0xbb>
lea    -0x120(%rbp),%rdi
lea    -0x230(%rbp),%rdx
lea    0xe3d(%rip),%rsi
lea    -0x124(%rbp),%rcx
call   1060 <sscanf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x20,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1206 <configReadID+0xb6>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <configReadID+0xcb>
jmp    1191 <configReadID+0x41>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configReadID>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r15
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
movl   $0xffffffff,0xc(%rsp)
ff
mov    $0xfffffffe,%eax
test   %rbp,%rbp
je     11f5 <configReadID+0xa5>
lea    0x110(%rsp),%r13
lea    0xe6e(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r14
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0xff,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e8 <configReadID+0x98>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <sscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11a0 <configReadID+0x50>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    11f5 <configReadID+0xa5>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    $0xfffffffe,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"%[a-zA-z0-9]:x:%i:\0A\00"
define i32 @configReadID(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca [256 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %6
store i32 -1, i32* %8
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %36
14: ; preds = %2
br label %15
15: ; preds = %32, %14
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 255, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %33
20: ; preds = %15
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32* %8)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = call i32 @strncmp(i8* %24, i8* %25, i32 32)
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %20
%29 = load i32*, i32** %6
%30 = call i32 @fclose(i32* %29)
%31 = load i32, i32* %8
store i32 %31, i32* %3
br label %37
32: ; preds = %20
br label %15
33: ; preds = %15
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
br label %36
36: ; preds = %33, %2
store i32 -2, i32* %3
br label %37
37: ; preds = %36, %28
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"%[a-zA-z0-9]:x:%i:\0A\00"
define i32 @configReadID(i8* nocapture %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = icmp eq i32* %6, null
br i1 %10, label %23, label %11
11: ; preds = %2, %14
%12 = call i32* @fgets(i8* %7, i32 255, i32* %6)
%13 = icmp eq i32* %12, null
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %9, i32* %4)
%16 = call i32 @strncmp(i8* %9, i8* %1, i32 32)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %11
18: ; preds = %14
%19 = call i32 @fclose(i32* %6)
%20 = load i32, i32* %4
br label %23
21: ; preds = %11
%22 = call i32 @fclose(i32* %6)
br label %23
23: ; preds = %2, %21, %18
%24 = phi i32 [ %20, %18 ], [ -2, %21 ], [ -2, %2 ]
ret i32 %24
}