#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ save(char *, int /*<<< orphan*/);
void ciao() {
  char fname[80];
  register char *c;
  for (;;) {
    printf("What would you like to call the saved version?\n");
    for (c = fname;; c++) {
      *c = getchar();
      if (*c == '\n')
        break;
    }
    *c = 0;
    if (access(fname, F_OK) < 0)
      break;
    printf("I can't use that one.\n");
    return;
  }
  save(fname, 0);
  printf("                    ^\n");
  printf("That should do it.  Gis revido.\n");
  exit(0);
}


x86 assembly (clang, -O0):
<ciao>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,%cl
mov    -0x58(%rbp),%rax
mov    %cl,(%rax)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1190 <ciao+0x40>
jmp    11a6 <ciao+0x56>
jmp    1195 <ciao+0x45>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    116c <ciao+0x1c>
mov    -0x58(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1060 <access@plt>
cmp    $0x0,%rax
jge    11ce <ciao+0x7e>
jmp    11e0 <ciao+0x90>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
call   1040 <save@plt>
lea    0xe55(%rip),%rdi
call   1030 <printf@plt>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<ciao>:
push   %rbx
sub    $0x50,%rsp
mov    %rsp,%rbx
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1170 <ciao+0x20>
movb   $0x0,-0x1(%rbx)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1060 <access@plt>
test   %rax,%rax
js     11ac <ciao+0x5c>
lea    0xe8d(%rip),%rdi
add    $0x50,%rsp
pop    %rbx
jmp    1030 <puts@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <save@plt>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"What would you like to call the saved version?\0A\00"
@F_OK = global i32 0
@.str.1 = [23 x i8] c"I can't use that one.\0A\00"
@.str.2 = [23 x i8] c" ^\0A\00"
@.str.3 = [33 x i8] c"That should do it. Gis revido.\0A\00"
define void @ciao() {
%1 = alloca [80 x i8]
%2 = alloca i8*
br label %3
3: ; preds = %0
%4 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
store i8* %5, i8** %2
br label %6
6: ; preds = %15, %3
%7 = call signext i8 (...) @getchar()
%8 = load i8*, i8** %2
store i8 %7, i8* %8
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %6
br label %18
14: ; preds = %6
br label %15
15: ; preds = %14
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
br label %6
18: ; preds = %13
%19 = load i8*, i8** %2
store i8 0, i8* %19
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%21 = load i32, i32* @F_OK
%22 = call i64 @access(i8* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
ret void
27: ; preds = %24
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%29 = call i32 @save(i8* %28, i32 0)
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@F_OK = global i32 0
@str = [47 x i8] c"What would you like to call the saved version?\00"
@str.4 = [22 x i8] c"I can't use that one.\00"
@str.5 = [22 x i8] c" ^\00"
@str.6 = [32 x i8] c"That should do it. Gis revido.\00"
define void @ciao() {
%1 = alloca [80 x i8]
%2 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = phi i8* [ %2, %0 ], [ %8, %4 ]
%6 = tail call signext i8 (...) @getchar()
store i8 %6, i8* %5
%7 = icmp eq i8 %6, 10
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %9, label %4
9: ; preds = %4
store i8 0, i8* %5
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* %2, i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.4, i64 0, i64 0))
ret void
15: ; preds = %9
%16 = call i32 @save(i8* %2, i32 0)
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.6, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
}