#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int /*<<< orphan*/);
int getidfile(const char *inifile, const char *idname, char *idfile) {
  FILE *fp = fopen(inifile, "r");
  char line[100] = {0};
  char name[30] = {0}, value[30] = {0};
  if (fp == NULL) {
    return -1;
  }
  while (!feof(fp)) {
    fgets(line, 100, fp);
    sscanf(line, "%s %s", name, value);
    if (strncmp(idname, name, strlen(idname)) == 0) {
      strcpy(idfile, value);
      fclose(fp);
      return 1;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<getidfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1070 <memset@plt>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1070 <memset@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x28(%rbp)
jne    120b <getidfile+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d6 <getidfile+0x146>
jmp    1210 <getidfile+0x80>
mov    -0x28(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    122e <getidfile+0x9e>
jmp    12cf <getidfile+0x13f>
lea    -0x90(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x64,%esi
call   1080 <fgets@plt>
lea    -0x90(%rbp),%rdi
lea    -0xb0(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
lea    0xda3(%rip),%rsi
call   10a0 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0xe0(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ca <getidfile+0x13a>
mov    -0x20(%rbp),%rdi
lea    -0xd0(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d6 <getidfile+0x146>
jmp    1210 <getidfile+0x80>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getidfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movl   $0x0,0xb0(%rsp)
movups %xmm0,0x3e(%rsp)
movaps %xmm0,0x30(%rsp)
movups %xmm0,0x1e(%rsp)
movaps %xmm0,0x10(%rsp)
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     128a <getidfile+0x10a>
mov    %rbp,0x8(%rsp)
lea    0x50(%rsp),%rbp
lea    0xdf4(%rip),%r13
lea    0x30(%rsp),%r14
lea    0x10(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1285 <getidfile+0x105>
mov    %rbp,%rdi
mov    $0x64,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1090 <sscanf@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1220 <getidfile+0xa0>
lea    0x10(%rsp),%rsi
mov    0x8(%rsp),%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    128a <getidfile+0x10a>
mov    $0xffffffff,%eax
add    $0xb8,%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 = [6 x i8] c"%s %s\00"
define i32 @getidfile(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 [30 x i8]
%11 = alloca [30 x 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 = bitcast [100 x i8]* %9 to i8*
%15 = bitcast [30 x i8]* %10 to i8*
%16 = bitcast [30 x i8]* %11 to i8*
%17 = load i32*, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %48
20: ; preds = %3
br label %21
21: ; preds = %46, %20
%22 = load i32*, i32** %8
%23 = call i32 @feof(i32* %22)
%24 = icmp ne i32 %23, 0
%25 = xor i1 %24, true
br i1 %25, label %26, label %47
26: ; preds = %21
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%28 = load i32*, i32** %8
%29 = call i32 @fgets(i8* %27, i32 100, i32* %28)
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%33 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32)
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [30 x i8], [30 x i8]* %10, i64 0, i64 0
%36 = load i8*, i8** %6
%37 = call i32 @strlen(i8* %36)
%38 = call i64 @strncmp(i8* %34, i8* %35, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %26
%41 = load i8*, i8** %7
%42 = getelementptr inbounds [30 x i8], [30 x i8]* %11, i64 0, i64 0
%43 = call i32 @strcpy(i8* %41, i8* %42)
%44 = load i32*, i32** %8
%45 = call i32 @fclose(i32* %44)
store i32 1, i32* %4
br label %48
46: ; preds = %26
br label %21
47: ; preds = %21
store i32 -1, i32* %4
br label %48
48: ; preds = %47, %40, %19
%49 = load i32, i32* %4
ret i32 %49
}

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