#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 != -1) {
    if (g_file_write(fd, "[keys]\n", 7) == -1) {
      g_writeln("problem writing to %s, maybe no rights", filename);
      g_file_close(fd);
      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    134a <save_all+0x1ca>
jmp    125e <save_all+0xde>
lea    -0x140(%rbp),%rdi
call   1030 <g_file_open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
je     131a <save_all+0x19a>
mov    -0x38(%rbp),%edi
lea    0xdbd(%rip),%rsi
mov    $0x7,%edx
call   1090 <g_file_write@plt>
cmp    $0xffffffff,%eax
jne    12bd <save_all+0x13d>
lea    -0x140(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
mov    -0x38(%rbp),%edi
call   1050 <g_file_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <save_all+0x1ca>
mov    -0x38(%rbp),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xd9f(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    0xd91(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    0x10(%rbp),%rdx
mov    0x18(%rbp),%ecx
lea    0xd83(%rip),%rsi
call   1060 <write_out_line@plt>
mov    -0x38(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    -0x34(%rbp),%ecx
lea    0xd75(%rip),%rsi
call   1060 <write_out_line@plt>
jmp    133b <save_all+0x1bb>
lea    -0x140(%rbp),%rsi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1040 <g_writeln@plt>
movl   $0x1,-0x4(%rbp)
jmp    134a <save_all+0x1ca>
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     12b2 <save_all+0x132>
mov    %r14d,%ebp
lea    0x10(%rsp),%rdi
call   1030 <g_file_open@plt>
cmp    $0xffffffff,%eax
je     12a9 <save_all+0x129>
mov    %eax,%r14d
lea    0xe13(%rip),%rsi
mov    %eax,%edi
mov    $0x7,%edx
call   1090 <g_file_write@plt>
cmp    $0xffffffff,%eax
je     12c7 <save_all+0x147>
lea    0xe26(%rip),%rsi
mov    %r14d,%edi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1060 <write_out_line@plt>
lea    0xe19(%rip),%rsi
mov    %r14d,%edi
mov    %r13,%rdx
mov    0xc(%rsp),%ecx
call   1060 <write_out_line@plt>
lea    0xe0b(%rip),%rsi
mov    %r14d,%edi
mov    0x150(%rsp),%rdx
mov    0x158(%rsp),%ecx
call   1060 <write_out_line@plt>
lea    0xdf5(%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    12e7 <save_all+0x167>
lea    0xddd(%rip),%rdi
jmp    12b9 <save_all+0x139>
lea    0xd60(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <g_writeln@plt>
jmp    12e2 <save_all+0x162>
lea    0xd78(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <g_writeln@plt>
mov    %r14d,%edi
call   1050 <g_file_close@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 %83
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 ne i32 %49, -1
br i1 %50, label %51, label %77
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 %60
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)
%58 = load i32, i32* %20
%59 = call i32 @g_file_close(i32 %58)
store i32 1, i32* %10
br label %83
60: ; preds = %51
%61 = load i32, i32* %20
%62 = load i8*, i8** %11
%63 = load i32, i32* %12
%64 = call i32 @write_out_line(i32 %61, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8* %62, i32 %63)
%65 = load i32, i32* %20
%66 = load i8*, i8** %13
%67 = load i32, i32* %14
%68 = call i32 @write_out_line(i32 %65, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %66, i32 %67)
%69 = load i32, i32* %20
%70 = load i8*, i8** %17
%71 = load i32, i32* %18
%72 = call i32 @write_out_line(i32 %69, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* %70, i32 %71)
%73 = load i32, i32* %20
%74 = load i8*, i8** %15
%75 = load i32, i32* %16
%76 = call i32 @write_out_line(i32 %73, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %74, i32 %75)
br label %80
77: ; preds = %46
%78 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%79 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %78)
store i32 1, i32* %10
br label %83
80: ; preds = %60
%81 = load i32, i32* %20
%82 = call i32 @g_file_close(i32 %81)
store i32 0, i32* %10
br label %83
83: ; preds = %80, %77, %55, %42
%84 = load i32, i32* %10
ret i32 %84
}

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 %44
27: ; preds = %22, %17
%28 = call i32 @g_file_open(i8* %11)
%29 = icmp eq i32 %28, -1
br i1 %29, label %42, label %30
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 %36
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)
%35 = call i32 @g_file_close(i32 %28)
br label %44
36: ; preds = %30
%37 = 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)
%38 = 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)
%39 = 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)
%40 = 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)
%41 = call i32 @g_file_close(i32 %28)
br label %44
42: ; preds = %27
%43 = call i32 (i8*, ...) @g_writeln(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i8* %11)
br label %44
44: ; preds = %36, %42, %33, %25
%45 = phi i32 [ 1, %25 ], [ 1, %33 ], [ 0, %36 ], [ 1, %42 ]
ret i32 %45
}