#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strncmp(char *, char *, int);
char tolower(char);
int user_confirmed(const char *action) {
  char answer[64];
  int i;
  if (action)
    printf("Going to %s.\n", action);
  printf("Are you sure (yes/no)? ");
  if (!fgets(answer, 64, stdin)) {
    return 0;
  }
  for (i = 0; i < 64 && answer[i]; i++)
    answer[i] = tolower(answer[i]);
  if (!strncmp("yes\n", answer, 64) || !strncmp("y\n", answer, 64)) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<user_confirmed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1169 <user_confirmed+0x29>
mov    -0x10(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11a3 <user_confirmed+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1250 <user_confirmed+0x110>
movl   $0x0,-0x54(%rbp)
xor    %eax,%eax
cmpl   $0x40,-0x54(%rbp)
mov    %al,-0x55(%rbp)
jge    11cb <user_confirmed+0x8b>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    11db <user_confirmed+0x9b>
jmp    1201 <user_confirmed+0xc1>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%edi
call   1060 <tolower@plt>
mov    %al,%cl
movslq -0x54(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11aa <user_confirmed+0x6a>
lea    -0x50(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     123d <user_confirmed+0xfd>
lea    -0x50(%rbp),%rsi
lea    0xe01(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1249 <user_confirmed+0x109>
movl   $0x1,-0x4(%rbp)
jmp    1250 <user_confirmed+0x110>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<user_confirmed>:
push   %rbx
sub    $0x40,%rsp
test   %rdi,%rdi
je     115b <user_confirmed+0x1b>
mov    %rdi,%rsi
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x40,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     11e7 <user_confirmed+0xa7>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%rsp,%rbx,1),%eax
test   %al,%al
je     11ad <user_confirmed+0x6d>
movsbl %al,%edi
call   1060 <tolower@plt>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x40,%rbx
jne    1190 <user_confirmed+0x50>
lea    0xe72(%rip),%rdi
mov    %rsp,%rsi
mov    $0x40,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11e2 <user_confirmed+0xa2>
lea    0xe5f(%rip),%rdi
mov    %rsp,%rsi
mov    $0x40,%edx
call   1030 <strncmp@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
jmp    11e7 <user_confirmed+0xa7>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Going to %s.\0A\00"
@.str.1 = [24 x i8] c"Are you sure (yes/no)? \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"yes\0A\00"
@.str.3 = [3 x i8] c"y\0A\00"
define i32 @user_confirmed(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %11
11: ; preds = %8, %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fgets(i8* %13, i32 64, i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %11
store i32 0, i32* %2
br label %53
18: ; preds = %11
store i32 0, i32* %5
br label %19
19: ; preds = %40, %18
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 64
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br label %29
29: ; preds = %22, %19
%30 = phi i1 [ false, %19 ], [ %28, %22 ]
br i1 %30, label %31, label %43
31: ; preds = %29
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = call signext i8 @tolower(i8 signext %35)
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 %38
store i8 %36, i8* %39
br label %40
40: ; preds = %31
%41 = load i32, i32* %5
%42 = add nsw i32 %41, 1
store i32 %42, i32* %5
br label %19
43: ; preds = %29
%44 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%45 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %44, i32 64)
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%49 = call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %48, i32 64)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %47, %43
store i32 1, i32* %2
br label %53
52: ; preds = %47
store i32 0, i32* %2
br label %53
53: ; preds = %52, %51, %17
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [14 x i8] c"Going to %s.\0A\00"
@.str.1 = [24 x i8] c"Are you sure (yes/no)? \00"
@stdin = global i32 0
@.str.2 = [5 x i8] c"yes\0A\00"
@.str.3 = [3 x i8] c"y\0A\00"
define i32 @user_confirmed(i8* %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %3, i32 64, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %7, %17
%13 = phi i64 [ %19, %17 ], [ 0, %7 ]
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = call signext i8 @tolower(i8 signext %15)
store i8 %18, i8* %14
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, 64
br i1 %20, label %21, label %12
21: ; preds = %17, %12
%22 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 64)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = call i32 @strncmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3, i32 64)
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %24, %21, %7
%29 = phi i32 [ 0, %7 ], [ 1, %21 ], [ %27, %24 ]
ret i32 %29
}