#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 */
typedef int /*<<< orphan*/ mpz_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
scalar_t__ mpz_out_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void WritePublicParametersToFile(mpz_t n, mpz_t u, char **error) {
  FILE *fd = fopen("public_params", "w");
  if (fd == NULL) {
    *error = "file open failed";
    return;
  }
  if (mpz_out_str(fd, 10, n) == 0) {
    *error = "file write failed";
    return;
  }
  fprintf(fd, "\n");
  if (mpz_out_str(fd, 10, u) == 0) {
    *error = "file write failed";
    return;
  }
  fclose(fd);
  *error = "success";
}


x86 assembly (clang, -O0):
<WritePublicParametersToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xea7(%rip),%rdi
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <WritePublicParametersToFile+0x47>
mov    -0x10(%rbp),%rax
lea    0xe91(%rip),%rcx
mov    %rcx,(%rax)
jmp    120a <WritePublicParametersToFile+0xca>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    $0xa,%esi
call   1050 <mpz_out_str@plt>
cmp    $0x0,%rax
jne    11b5 <WritePublicParametersToFile+0x75>
mov    -0x10(%rbp),%rax
lea    0xe74(%rip),%rcx
mov    %rcx,(%rax)
jmp    120a <WritePublicParametersToFile+0xca>
mov    -0x18(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
mov    $0xa,%esi
call   1050 <mpz_out_str@plt>
cmp    $0x0,%rax
jne    11f3 <WritePublicParametersToFile+0xb3>
mov    -0x10(%rbp),%rax
lea    0xe36(%rip),%rcx
mov    %rcx,(%rax)
jmp    120a <WritePublicParametersToFile+0xca>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
lea    0xe2e(%rip),%rcx
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WritePublicParametersToFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%ebp
lea    0xeaa(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b8 <WritePublicParametersToFile+0x78>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xa,%esi
mov    %ebp,%edx
call   1050 <mpz_out_str@plt>
lea    0xea1(%rip),%rbp
test   %rax,%rax
je     11bf <WritePublicParametersToFile+0x7f>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r15d,%edx
call   1050 <mpz_out_str@plt>
test   %rax,%rax
je     11bf <WritePublicParametersToFile+0x7f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe7d(%rip),%rbp
jmp    11bf <WritePublicParametersToFile+0x7f>
lea    0xe51(%rip),%rbp
mov    %rbp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"public_params\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"file open failed\00"
@.str.3 = [18 x i8] c"file write failed\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [8 x i8] c"success\00"
define void @WritePublicParametersToFile(i32 %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8** %2, i8*** %6
%8 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %7
%9 = load i32*, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i8**, i8*** %6
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %12
br label %33
13: ; preds = %3
%14 = load i32*, i32** %7
%15 = load i32, i32* %4
%16 = call i64 @mpz_out_str(i32* %14, i32 10, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i8**, i8*** %6
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %19
br label %33
20: ; preds = %13
%21 = load i32*, i32** %7
%22 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = load i32*, i32** %7
%24 = load i32, i32* %5
%25 = call i64 @mpz_out_str(i32* %23, i32 10, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = load i8**, i8*** %6
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %28
br label %33
29: ; preds = %20
%30 = load i32*, i32** %7
%31 = call i32 @fclose(i32* %30)
%32 = load i8**, i8*** %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %32
br label %33
33: ; preds = %29, %27, %18, %11
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"public_params\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [17 x i8] c"file open failed\00"
@.str.3 = [18 x i8] c"file write failed\00"
@.str.5 = [8 x i8] c"success\00"
define void @WritePublicParametersToFile(i32 %0, i32 %1, i8** nocapture writeonly %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3
%7 = tail call i64 @mpz_out_str(i32* %4, i32 10, i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %6
%10 = tail call i32 @fputc(i32 10, i32* %4)
%11 = tail call i64 @mpz_out_str(i32* %4, i32 10, i32 %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @fclose(i32* %4)
br label %15
15: ; preds = %9, %6, %3, %13
%16 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %13 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), %6 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), %9 ]
store i8* %16, i8** %2
ret void
}