#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*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char const *);
char *strstr(char *, char const *);
int get_type_name(FILE *fp, char *type_name) {
  int ret = -1;
  char *line = NULL, *p;
  size_t len;
  const char *match_key = "type = ";
  int is_done = 0;
  while (!is_done) {
    if (getline(&line, &len, fp) < 0) {
      break;
    }
    if ((p = strstr(line, match_key)) != NULL) {
      ret = 1;
      is_done = 1;
      p += strlen(match_key);
      strcpy(type_name, p);
      type_name[strlen(type_name) - 1] = '\0';
    }
  }
  free(line);
  return ret;
}


x86 assembly (clang, -O0):
<get_type_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1197 <get_type_name+0x47>
jmp    1223 <get_type_name+0xd3>
mov    -0x8(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0x0,%rax
jge    11b7 <get_type_name+0x67>
jmp    1223 <get_type_name+0xd3>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     121e <get_type_name+0xce>
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1181 <get_type_name+0x31>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_type_name>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    %rsp,%r15
lea    0x8(%rsp),%r12
lea    0xe86(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <getline@plt>
test   %rax,%rax
js     11c8 <get_type_name+0x78>
mov    (%rsp),%rdi
mov    %r13,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1180 <get_type_name+0x30>
add    $0x7,%rax
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
movb   $0x0,-0x1(%rax,%r14,1)
mov    $0x1,%ebx
jmp    11cd <get_type_name+0x7d>
mov    $0xffffffff,%ebx
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"type = \00"
define i32 @get_type_name(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store i8* null, i8** %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 0, i32* %10
br label %11
11: ; preds = %38, %2
%12 = load i32, i32* %10
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %39
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = call i64 @getline(i8** %6, i64* %8, i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
br label %39
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = load i8*, i8** %9
%23 = call i8* @strstr(i8* %21, i8* %22)
store i8* %23, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %38
25: ; preds = %20
store i32 1, i32* %5
store i32 1, i32* %10
%26 = load i8*, i8** %9
%27 = call i64 @strlen(i8* %26)
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i64 %27
store i8* %29, i8** %7
%30 = load i8*, i8** %4
%31 = load i8*, i8** %7
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %4
%34 = load i8*, i8** %4
%35 = call i64 @strlen(i8* %34)
%36 = sub i64 %35, 1
%37 = getelementptr inbounds i8, i8* %33, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %25, %20
br label %11
39: ; preds = %19, %11
%40 = load i8*, i8** %6
%41 = call i32 @free(i8* %40)
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
@.str = [8 x i8] c"type = \00"
define i32 @get_type_name(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
br label %7
7: ; preds = %10, %2
%8 = call i64 @getline(i8** %3, i64* %4, i32* %0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = call i8* @strstr(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %7, label %14
14: ; preds = %10
%15 = getelementptr inbounds i8, i8* %12, i64 7
%16 = call i32 @strcpy(i8* %1, i8* %15)
%17 = call i64 @strlen(i8* dereferenceable(1) %1)
%18 = add i64 %17, -1
%19 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %19
br label %20
20: ; preds = %7, %14
%21 = phi i32 [ 1, %14 ], [ -1, %7 ]
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
ret i32 %21
}