#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*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ *stdout;
char tolower(char);
FILE *inputStampaSuFile() {
  FILE *fp;
  char c[3], f[100];
  printf("Stampa su file? [s/n] ");
  scanf("%s", c);
  if (tolower(c[0]) == 's') {
    printf("Inserisci il nome del file: ");
    scanf("%s", f);
    if ((fp = fopen(f, "w")) == NULL) {
      printf("Errore! Impossibile aprire il file \"%s\"", f);
      printf("Stampo a video...\n");
      return stdout;
    } else {
      return fp;
    }
  } else {
    return stdout;
  }
}


x86 assembly (clang, -O0):
<inputStampaSuFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x13(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1050 <scanf@plt>
movsbl -0x13(%rbp),%edi
call   1040 <tolower@plt>
movsbl %al,%eax
cmp    $0x73,%eax
jne    11fa <inputStampaSuFile+0xba>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe80(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11ed <inputStampaSuFile+0xad>
lea    -0x80(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <inputStampaSuFile+0xc8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1208 <inputStampaSuFile+0xc8>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputStampaSuFile>:
push   %rbx
sub    $0x80,%rsp
lea    0xea1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    0xd(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xd(%rsp),%edi
call   1050 <tolower@plt>
cmp    $0x73,%al
jne    11da <inputStampaSuFile+0x8a>
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7d(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11e4 <inputStampaSuFile+0x94>
lea    0xe77(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Stampa su file? [s/n] \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"Inserisci il nome del file: \00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"Errore! Impossibile aprire il file \22%s\22\00"
@.str.5 = [19 x i8] c"Stampo a video...\0A\00"
@stdout = global i32* null
define i32* @inputStampaSuFile() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [3 x i8]
%4 = alloca [100 x i8]
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%9 = load i8, i8* %8
%10 = call signext i8 @tolower(i8 signext %9)
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 115
br i1 %12, label %13, label %27
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %2
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%24 = load i32*, i32** @stdout
store i32* %24, i32** %1
br label %29
25: ; preds = %13
%26 = load i32*, i32** %2
store i32* %26, i32** %1
br label %29
27: ; preds = %0
%28 = load i32*, i32** @stdout
store i32* %28, i32** %1
br label %29
29: ; preds = %27, %25, %20
%30 = load i32*, i32** %1
ret i32* %30
}

LLVM IR (-O2):
@.str = [23 x i8] c"Stampa su file? [s/n] \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"Inserisci il nome del file: \00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [40 x i8] c"Errore! Impossibile aprire il file \22%s\22\00"
@stdout = global i32* null
@str = [18 x i8] c"Stampo a video...\00"
define i32* @inputStampaSuFile() {
%1 = alloca [3 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = load i8, i8* %3
%8 = call signext i8 @tolower(i8 signext %7)
%9 = icmp eq i8 %8, 115
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%18 = load i32*, i32** @stdout
br label %21
19: ; preds = %0
%20 = load i32*, i32** @stdout
br label %21
21: ; preds = %10, %19, %15
%22 = phi i32* [ %18, %15 ], [ %20, %19 ], [ %13, %10 ]
ret i32* %22
}