#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fs_write(char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int sprintf(char *, char *, long);
void generate_key_file(long success_key) {
  char *path = "./key";
  char key[20];
  int length;
  length = sprintf(key, "%li", success_key);
  if (fs_write(path, (unsigned char *)key, length) != length) {
    printf("\nerror writing key file\n");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<generate_key_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xead(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea0(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1040 <fs_write@plt>
cmp    -0x34(%rbp),%eax
je     119d <generate_key_file+0x5d>
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_key_file>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rdx
lea    0xeb6(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <sprintf@plt>
mov    %eax,%ebp
lea    0xe9c(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <fs_write@plt>
cmp    %ebp,%eax
jne    1179 <generate_key_file+0x39>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"./key\00"
@.str.1 = [4 x i8] c"%li\00"
@.str.2 = [25 x i8] c"\0Aerror writing key file\0A\00"
define void @generate_key_file(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca i32
store i64 %0, i64* %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %3
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = load i64, i64* %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %7)
store i32 %8, i32* %5
%9 = load i8*, i8** %3
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* %5
%12 = call i32 @fs_write(i8* %9, i8* %10, i32 %11)
%13 = load i32, i32* %5
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %1
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"./key\00"
@.str.1 = [4 x i8] c"%li\00"
@str = [24 x i8] c"\0Aerror writing key file\00"
define void @generate_key_file(i64 %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %0)
%5 = call i32 @fs_write(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %4)
%6 = icmp eq i32 %5, %4
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %1
ret void
}