#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 hive {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int errno;
int /*<<< orphan*/ export_subkey(struct hive *, int, char *, char *,
                                 int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
char *strerror(int);
void export_key(struct hive *hdesc, int nkofs, char *name, char *filename,
                char *prefix) {
  FILE *file;
  file = fopen(filename, "w");
  if (!file) {
    printf("export: Cannot open file '%s'. %s (%d).\n", filename,
           strerror(errno), errno);
    return;
  }
  printf("Exporting to file '%s'...\n", filename);
  fprintf(file, "Windows Registry Editor Version 5.00\r\n");
  export_subkey(hdesc, nkofs, name, prefix, file);
  fprintf(file, "\r\n");
  fclose(file);
}


x86 assembly (clang, -O0):
<export_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d3 <export_key+0x73>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
mov    0x2e22(%rip),%rax
mov    (%rax),%ecx
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1226 <export_key+0xc6>
mov    -0x20(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   1040 <export_subkey@plt>
mov    -0x30(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_key>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %esi,%r12d
mov    %rdi,%r13
lea    0xe7f(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fe <export_key+0x9e>
mov    %rax,%rbx
lea    0xe93(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
mov    $0x26,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r13,%rdi
mov    %r12d,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1040 <export_subkey@plt>
lea    0xe94(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2ddb(%rip),%rbx
mov    (%rbx),%edi
call   1080 <strerror@plt>
mov    (%rbx),%ecx
lea    0xded(%rip),%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
%struct.hive = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [41 x i8] c"export: Cannot open file '%s'. %s (%d).\0A\00"
@errno = global i32 0
@.str.2 = [27 x i8] c"Exporting to file '%s'...\0A\00"
@.str.3 = [39 x i8] c"Windows Registry Editor Version 5.00\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @export_key(%struct.hive* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca %struct.hive*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store %struct.hive* %0, %struct.hive** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%12 = load i8*, i8** %9
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp ne i32* %14, null
br i1 %15, label %22, label %16
16: ; preds = %5
%17 = load i8*, i8** %9
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = load i32, i32* @errno
%21 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %19, i32 %20)
br label %37
22: ; preds = %5
%23 = load i8*, i8** %9
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i32*, i32** %11
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%27 = load %struct.hive*, %struct.hive** %6
%28 = load i32, i32* %7
%29 = load i8*, i8** %8
%30 = load i8*, i8** %10
%31 = load i32*, i32** %11
%32 = call i32 @export_subkey(%struct.hive* %27, i32 %28, i8* %29, i8* %30, i32* %31)
%33 = load i32*, i32** %11
%34 = call i32 @fprintf(i32* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32*, i32** %11
%36 = call i32 @fclose(i32* %35)
br label %37
37: ; preds = %22, %16
ret void
}

LLVM IR (-O2):
%struct.hive = type { i32 }
@.str = [2 x i8] c"w\00"
@.str.1 = [41 x i8] c"export: Cannot open file '%s'. %s (%d).\0A\00"
@errno = global i32 0
@.str.2 = [27 x i8] c"Exporting to file '%s'...\0A\00"
@.str.3 = [39 x i8] c"Windows Registry Editor Version 5.00\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @export_key(%struct.hive* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = load i32, i32* @errno
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* %10, i32 %11)
br label %19
13: ; preds = %5
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i64 38, i64 1, i32* %6)
%16 = tail call i32 @export_subkey(%struct.hive* %0, i32 %1, i8* %2, i8* %4, i32* %6)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 2, i64 1, i32* %6)
%18 = tail call i32 @fclose(i32* %6)
br label %19
19: ; preds = %13, %8
ret void
}