#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ __fpurge(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcasecmp(char *, char *);
char *read_string(char *str) {
  __fpurge(stdin);
  *str = -1;
  gets(str);
  if (!strcasecmp(str, "sair")) {
    printf("Finalizando o programa a pedido do usuario.\n");
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<read_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1040 <__fpurge@plt>
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x10(%rbp),%rdi
call   1060 <gets@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%eax
jne    11ad <read_string+0x5d>
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
call   1050 <__fpurge@plt>
movb   $0xff,(%rbx)
mov    %rbx,%rdi
call   1060 <gets@plt>
lea    0xe8c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcasecmp@plt>
test   %eax,%eax
je     1182 <read_string+0x32>
pop    %rbx
ret
lea    0xe7c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"sair\00"
@.str.1 = [45 x i8] c"Finalizando o programa a pedido do usuario.\0A\00"
@EXIT_SUCCESS = global i32 0
define i8* @read_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i32, i32* @stdin
%5 = call i32 @__fpurge(i32 %4)
%6 = load i8*, i8** %3
store i8 -1, i8* %6
%7 = load i8*, i8** %3
%8 = call i32 @gets(i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 @strcasecmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"sair\00"
@EXIT_SUCCESS = global i32 0
@str = [44 x i8] c"Finalizando o programa a pedido do usuario.\00"
define noalias i8* @read_string(i8* %0) {
%2 = load i32, i32* @stdin
%3 = tail call i32 @__fpurge(i32 %2)
store i8 -1, i8* %0
%4 = tail call i32 @gets(i8* %0)
%5 = tail call i32 @strcasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
ret i8* undef
}