#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*/ g_file_close(int);
scalar_t__ g_file_delete(char *);
scalar_t__ g_file_exist(char *);
int g_file_open(char *);
int g_file_write(int, char *, int);
int /*<<< orphan*/ g_strncpy(char *, char const *, int);
int /*<<< orphan*/ g_writeln(char *, ...);
int /*<<< orphan*/ write_out_line(int, char *, char *, int);
int save_all(char *e_data, int e_len, char *n_data, int n_len, char *d_data,
             int d_len, char *sign_data, int sign_len,
             const char *path_and_file_name) {
  int fd;
  char filename[256];
  if (path_and_file_name == 0) {
    g_strncpy(filename, "rsakeys.ini", 255);
  } else {
    g_strncpy(filename, path_and_file_name, 255);
  }
  g_writeln("saving to %s", filename);
  g_writeln("");
  if (g_file_exist(filename)) {
    if (g_file_delete(filename) == 0) {
      g_writeln("problem deleting %s, maybe no rights", filename);
      return 1;
    }
  }
  fd = g_file_open(filename);
  if (fd > 0) {
    if (g_file_write(fd, "[keys]\n", 7) == -1) {
      g_writeln("problem writing to %s, maybe no rights", filename);
      return 1;
    }
    write_out_line(fd, "pub_exp", e_data, e_len);
    write_out_line(fd, "pub_mod", n_data, n_len);
    write_out_line(fd, "pub_sig", sign_data, sign_len);
    write_out_line(fd, "pri_exp", d_data, d_len);
  } else {
    g_writeln("problem opening %s, maybe no rights", filename);
    return 1;
  }
  g_file_close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<save_all>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
cmpq   $0x0,0x20(%rbp)
jne    11d4 <save_all+0x54>
lea    -0x140(%rbp),%rdi
lea    0xe3b(%rip),%rsi
mov    $0xff,%edx
call   10a0 <g_strncpy@plt>
jmp    11e9 <save_all+0x69>
lea    -0x140(%rbp),%rdi
mov    0x20(%rbp),%rsi
mov    $0xff,%edx
call   10a0 <g_strncpy@plt>
lea    -0x140(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
lea    -0x140(%rbp),%rdi
call   1070 <g_file_exist@plt>
cmp    $0x0,%rax
je     125e <save_all+0xde>
lea    -0x140(%rbp),%rdi
call   1080 <g_file_delete@plt>
cmp    $0x0,%rax
jne    1259 <save_all+0xd9>
lea    -0x140(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <save_all+0x1c2>
jmp    125e <save_all+0xde>
lea    -0x140(%rbp),%rdi
call   1030 <g_file_open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    1312 <save_all+0x192>
mov    -0x38(%rbp),%edi
lea    0xdbd(%rip),%rsi
mov    $0x7,%edx
call   1090 <g_file_write@plt>
cmp    $0xffffffff,%eax
jne    12b5 <save_all+0x135>
lea    -0x140(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <save_all+0x1c2>
mov    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xda7(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xd99(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%ecx
lea    0xd8b(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%ecx
lea    0xd7d(%rip),%rsi
call   1060 <write_out_line@plt>
jmp    1333 <save_all+0x1b3>
lea    -0x140(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <save_all+0x1c2>
mov    -0x38(%rbp),%edi
call   1050 <g_file_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_all>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %r9d,%r14d
mov    %r8,%rbx
mov    %esi,%r15d
mov    %rdi,%r12
mov    0x160(%rsp),%rsi
test   %rsi,%rsi
mov    %ecx,0xc(%rsp)
mov    %rdx,%r13
jne    11b8 <save_all+0x38>
lea    0xe48(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0xff,%edx
call   10a0 <g_strncpy@plt>
lea    0xe3e(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <g_writeln@plt>
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1040 <g_writeln@plt>
mov    %rbp,%rdi
call   1070 <g_file_exist@plt>
test   %rax,%rax
je     120b <save_all+0x8b>
lea    0x10(%rsp),%rdi
call   1080 <g_file_delete@plt>
test   %rax,%rax
je     12ad <save_all+0x12d>
mov    %r14d,%ebp
lea    0x10(%rsp),%rdi
call   1030 <g_file_open@plt>
test   %eax,%eax
jle    12a4 <save_all+0x124>
mov    %eax,%r14d
lea    0xe14(%rip),%rsi
mov    %eax,%edi
mov    $0x7,%edx
call   1090 <g_file_write@plt>
cmp    $0xffffffff,%eax
je     12b6 <save_all+0x136>
lea    0xe2b(%rip),%rsi
mov    %r14d,%edi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1060 <write_out_line@plt>
lea    0xe1e(%rip),%rsi
mov    %r14d,%edi
mov    %r13,%rdx
mov    0xc(%rsp),%ecx
call   1060 <write_out_line@plt>
lea    0xe10(%rip),%rsi
mov    %r14d,%edi
mov    0x150(%rsp),%rdx
mov    0x158(%rsp),%ecx
call   1060 <write_out_line@plt>
lea    0xdfa(%rip),%rsi
mov    %r14d,%edi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1060 <write_out_line@plt>
mov    %r14d,%edi
call   1050 <g_file_close@plt>
xor    %eax,%eax
jmp    12ce <save_all+0x14e>
lea    0xde2(%rip),%rdi
jmp    12bd <save_all+0x13d>
lea    0xd65(%rip),%rdi
jmp    12bd <save_all+0x13d>
lea    0xd89(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <g_writeln@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"rsakeys.ini\00"
@.str.1 = [13 x i8] c"saving to %s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [37 x i8] c"problem deleting %s, maybe no rights\00"
@.str.4 = [8 x i8] c"[keys]\0A\00"
@.str.5 = [39 x i8] c"problem writing to %s, maybe no rights\00"
@.str.6 = [8 x i8] c"pub_exp\00"
@.str.7 = [8 x i8] c"pub_mod\00"
@.str.8 = [8 x i8] c"pub_sig\00"
@.str.9 = [8 x i8] c"pri_exp\00"
@.str.10 = [36 x i8] c"problem opening %s, maybe no rights\00"
define i32 @save_all(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, i8* %6, i32 %7, i8* %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i8*
%20 = alloca i32
%21 = alloca [256 x i8]
store i8* %0, i8** %11
store i32 %1, i32* %12
store i8* %2, i8** %13
store i32 %3, i32* %14
store i8* %4, i8** %15
store i32 %5, i32* %16
store i8* %6, i8** %17
store i32 %7, i32* %18
store i8* %8, i8** %19
%22 = load i8*, i8** %19
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %9
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%26 = call i32 @g_strncpy(i8* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 255)
br label %31
27: ; preds = %9
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%29 = load i8*, i8** %19
%30 = call i32 @g_strncpy(i8* %28, i8* %29, i32 255)
br label %31
31: ; preds = %27, %24
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%33 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%36 = call i64 @g_file_exist(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%40 = call i64 @g_file_delete(i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %38
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%44 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %43)
store i32 1, i32* %10
br label %81
45: ; preds = %38
br label %46
46: ; preds = %45, %31
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%48 = call i32 @g_file_open(i8* %47)
store i32 %48, i32* %20
%49 = load i32, i32* %20
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %75
51: ; preds = %46
%52 = load i32, i32* %20
%53 = call i32 @g_file_write(i32 %52, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%57 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %56)
store i32 1, i32* %10
br label %81
58: ; preds = %51
%59 = load i32, i32* %20
%60 = load i8*, i8** %11
%61 = load i32, i32* %12
%62 = call i32 @write_out_line(i32 %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %60, i32 %61)
%63 = load i32, i32* %20
%64 = load i8*, i8** %13
%65 = load i32, i32* %14
%66 = call i32 @write_out_line(i32 %63, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %64, i32 %65)
%67 = load i32, i32* %20
%68 = load i8*, i8** %17
%69 = load i32, i32* %18
%70 = call i32 @write_out_line(i32 %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %68, i32 %69)
%71 = load i32, i32* %20
%72 = load i8*, i8** %15
%73 = load i32, i32* %16
%74 = call i32 @write_out_line(i32 %71, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %72, i32 %73)
br label %78
75: ; preds = %46
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%77 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %76)
store i32 1, i32* %10
br label %81
78: ; preds = %58
%79 = load i32, i32* %20
%80 = call i32 @g_file_close(i32 %79)
store i32 0, i32* %10
br label %81
81: ; preds = %78, %75, %55, %42
%82 = load i32, i32* %10
ret i32 %82
}

LLVM IR (-O2):
@.str = [12 x i8] c"rsakeys.ini\00"
@.str.1 = [13 x i8] c"saving to %s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [37 x i8] c"problem deleting %s, maybe no rights\00"
@.str.4 = [8 x i8] c"[keys]\0A\00"
@.str.5 = [39 x i8] c"problem writing to %s, maybe no rights\00"
@.str.6 = [8 x i8] c"pub_exp\00"
@.str.7 = [8 x i8] c"pub_mod\00"
@.str.8 = [8 x i8] c"pub_sig\00"
@.str.9 = [8 x i8] c"pri_exp\00"
@.str.10 = [36 x i8] c"problem opening %s, maybe no rights\00"
define i32 @save_all(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5, i8* %6, i32 %7, i8* %8) {
%10 = alloca [256 x i8]
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%12 = icmp eq i8* %8, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @g_strncpy(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 255)
br label %17
15: ; preds = %9
%16 = call i32 @g_strncpy(i8* %11, i8* %8, i32 255)
br label %17
17: ; preds = %15, %13
%18 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%19 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
%20 = call i64 @g_file_exist(i8* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = call i64 @g_file_delete(i8* %11)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %11)
br label %43
27: ; preds = %22, %17
%28 = call i32 @g_file_open(i8* %11)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = call i32 @g_file_write(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 7)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %11)
br label %43
35: ; preds = %30
%36 = call i32 @write_out_line(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 %1)
%37 = call i32 @write_out_line(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %2, i32 %3)
%38 = call i32 @write_out_line(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %6, i32 %7)
%39 = call i32 @write_out_line(i32 %28, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %4, i32 %5)
%40 = call i32 @g_file_close(i32 %28)
br label %43
41: ; preds = %27
%42 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %11)
br label %43
43: ; preds = %35, %41, %33, %25
%44 = phi i32 [ 1, %25 ], [ 1, %33 ], [ 0, %35 ], [ 1, %41 ]
ret i32 %44
}