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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
FILE *save() {
  FILE *fichier = NULL;
  char nom[30];
  while (fichier == NULL) {
    printf("Ou sauvegarder ?\n");
    scanf("%s", nom);
    fichier = fopen(nom, "r");
    if (fichier != NULL) {
      fclose(fichier);
      printf("Ce fichier existe deja.\n");
      fichier = NULL;
    } else
      fichier = fopen(nom, "w");
  }
  return fichier;
}


x86 assembly (clang, -O0):
<save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11d1 <save+0x91>
lea    0xe9e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b8 <save+0x78>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11cc <save+0x8c>
lea    -0x30(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
jmp    1150 <save+0x10>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xeb2(%rip),%r14
lea    0xea4(%rip),%r15
mov    %rsp,%rbx
lea    0xe9d(%rip),%r12
lea    0xe98(%rip),%r13
lea    0xea4(%rip),%rbp
jmp    1190 <save+0x50>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    11ca <save+0x8a>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1180 <save+0x40>
mov    %rax,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
test   %rax,%rax
je     1190 <save+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Ou sauvegarder ?\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [25 x i8] c"Ce fichier existe deja.\0A\00"
@.str.4 = [2 x i8] c"w\00"
define i32* @save() {
%1 = alloca i32*
%2 = alloca [30 x i8]
store i32* null, i32** %1
br label %3
3: ; preds = %21, %0
%4 = load i32*, i32** %1
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %22
6: ; preds = %3
%7 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %1
%12 = load i32*, i32** %1
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = load i32*, i32** %1
%16 = call i32 @fclose(i32* %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
store i32* null, i32** %1
br label %21
18: ; preds = %6
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %1
br label %21
21: ; preds = %18, %14
br label %3
22: ; preds = %3
%23 = load i32*, i32** %1
ret i32* %23
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@str = [17 x i8] c"Ou sauvegarder ?\00"
@str.5 = [24 x i8] c"Ce fichier existe deja.\00"
define i32* @save() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %13
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = call i32 @fclose(i32* %6)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %13
11: ; preds = %3
%12 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %13
13: ; preds = %11, %8
%14 = phi i32* [ null, %8 ], [ %12, %11 ]
%15 = icmp eq i32* %14, null
br i1 %15, label %3, label %16
16: ; preds = %13
ret i32* %14
}