#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 fcb {
  int dummy;
};

/* Variables and functions */
int get_kf_version(struct fcb *, char *);
int kf7_open_key(struct fcb *, char *, int, int);
int open_key(struct fcb *f, char id[], int lc, int read_only) {
  int err, version;
  version = get_kf_version(f, id);
  if (version == 7)
    err = kf7_open_key(f, id, lc, read_only);
  else if (version <= 6)
    err = 14;
  else
    err = 14;
  return (err);
}


x86 assembly (clang, -O0):
<open_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <get_kf_version@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jne    116b <open_key+0x4b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1040 <kf7_open_key@plt>
mov    %eax,-0x1c(%rbp)
jmp    118d <open_key+0x6d>
cmpl   $0x6,-0x20(%rbp)
jg     1181 <open_key+0x61>
movl   $0xe,-0x1c(%rbp)
jmp    1188 <open_key+0x68>
movl   $0xe,-0x1c(%rbp)
jmp    118d <open_key+0x6d>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_key>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1030 <get_kf_version@plt>
cmp    $0x7,%eax
jne    1158 <open_key+0x38>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <kf7_open_key@plt>
mov    $0xe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.fcb = type { i32 }
define i32 @open_key(%struct.fcb* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.fcb*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.fcb* %0, %struct.fcb** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load %struct.fcb*, %struct.fcb** %5
%12 = load i8*, i8** %6
%13 = call i32 @get_kf_version(%struct.fcb* %11, i8* %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 7
br i1 %15, label %16, label %22
16: ; preds = %4
%17 = load %struct.fcb*, %struct.fcb** %5
%18 = load i8*, i8** %6
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = call i32 @kf7_open_key(%struct.fcb* %17, i8* %18, i32 %19, i32 %20)
store i32 %21, i32* %9
br label %28
22: ; preds = %4
%23 = load i32, i32* %10
%24 = icmp sle i32 %23, 6
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 14, i32* %9
br label %27
26: ; preds = %22
store i32 14, i32* %9
br label %27
27: ; preds = %26, %25
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %9
ret i32 %29
}

LLVM IR (-O2):
%struct.fcb = type { i32 }
define i32 @open_key(%struct.fcb* %0, i8* %1, i32 %2, i32 %3) {
%5 = tail call i32 @get_kf_version(%struct.fcb* %0, i8* %1)
%6 = icmp eq i32 %5, 7
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @kf7_open_key(%struct.fcb* %0, i8* %1, i32 %2, i32 %3)
br label %9
9: ; preds = %4, %7
%10 = phi i32 [ %8, %7 ], [ 14, %4 ]
ret i32 %10
}