#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 */
struct cw_KTV_Reader {
  int dummy;
};

/* Variables and functions */
int read_key(struct cw_KTV_Reader *, char *, int);
int read_type(struct cw_KTV_Reader *, char *, int);
int read_val(struct cw_KTV_Reader *, char *, int);
int cw_ktv_parse_string(struct cw_KTV_Reader *r, char *key, char *type,
                        char *val) {
  int n;
  n = read_key(r, key, 1024);
  n = read_type(r, type, 200);
  if (n == 1)
    return -1;
  n = read_val(r, val, 200);
  return n;
}


x86 assembly (clang, -O0):
<cw_ktv_parse_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read_key@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0xc8,%edx
call   1030 <read_type@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x1,-0x2c(%rbp)
jne    1188 <cw_ktv_parse_string+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a3 <cw_ktv_parse_string+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0xc8,%edx
call   1040 <read_val@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_ktv_parse_string>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    $0x400,%edx
call   1050 <read_key@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0xc8,%edx
call   1030 <read_type@plt>
cmp    $0x1,%eax
jne    1168 <cw_ktv_parse_string+0x38>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xc8,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <read_val@plt>

LLVM IR (-O0):
%struct.cw_KTV_Reader = type { i32 }
define i32 @cw_ktv_parse_string(%struct.cw_KTV_Reader* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.cw_KTV_Reader*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store %struct.cw_KTV_Reader* %0, %struct.cw_KTV_Reader** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load %struct.cw_KTV_Reader*, %struct.cw_KTV_Reader** %6
%12 = load i8*, i8** %7
%13 = call i32 @read_key(%struct.cw_KTV_Reader* %11, i8* %12, i32 1024)
store i32 %13, i32* %10
%14 = load %struct.cw_KTV_Reader*, %struct.cw_KTV_Reader** %6
%15 = load i8*, i8** %8
%16 = call i32 @read_type(%struct.cw_KTV_Reader* %14, i8* %15, i32 200)
store i32 %16, i32* %10
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %20
19: ; preds = %4
store i32 -1, i32* %5
br label %25
20: ; preds = %4
%21 = load %struct.cw_KTV_Reader*, %struct.cw_KTV_Reader** %6
%22 = load i8*, i8** %9
%23 = call i32 @read_val(%struct.cw_KTV_Reader* %21, i8* %22, i32 200)
store i32 %23, i32* %10
%24 = load i32, i32* %10
store i32 %24, i32* %5
br label %25
25: ; preds = %20, %19
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.cw_KTV_Reader = type { i32 }
define i32 @cw_ktv_parse_string(%struct.cw_KTV_Reader* %0, i8* %1, i8* %2, i8* %3) {
%5 = tail call i32 @read_key(%struct.cw_KTV_Reader* %0, i8* %1, i32 1024)
%6 = tail call i32 @read_type(%struct.cw_KTV_Reader* %0, i8* %2, i32 200)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %4
%9 = tail call i32 @read_val(%struct.cw_KTV_Reader* %0, i8* %3, i32 200)
br label %10
10: ; preds = %4, %8
%11 = phi i32 [ %9, %8 ], [ -1, %4 ]
ret i32 %11
}