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

/* Variables and functions */
scalar_t__ malloc(int);
char *ft_get_key(char *str) {
  char *key;
  int i;
  int j;
  i = 0;
  j = 3;
  key = (char *)malloc(sizeof(key) * 4);
  while (str[i] != '\n')
    i++;
  key[j] = '\0';
  while (j >= 0) {
    key[--j] = str[--i];
  }
  return (key);
}


x86 assembly (clang, -O0):
<ft_get_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
mov    $0x20,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     115b <ft_get_key+0x4b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <ft_get_key+0x28>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x18(%rbp)
jl     119c <ft_get_key+0x8c>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1167 <ft_get_key+0x57>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_get_key>:
push   %rbx
mov    %rdi,%rbx
mov    $0x20,%edi
call   1030 <malloc@plt>
movabs $0xffffffff00000000,%rcx
ff ff ff
movabs $0x100000000,%rdx
mov    %rbx,%rsi
cs nopw 0x0(%rax,%rax,1)
nop
add    %rdx,%rcx
cmpb   $0xa,(%rsi)
lea    0x1(%rsi),%rsi
jne    1140 <ft_get_key+0x30>
movb   $0x0,0x3(%rax)
sar    $0x20,%rcx
mov    -0x1(%rcx,%rbx,1),%dl
mov    %dl,0x2(%rax)
mov    -0x2(%rcx,%rbx,1),%dl
mov    %dl,0x1(%rax)
mov    -0x3(%rcx,%rbx,1),%dl
mov    %dl,(%rax)
mov    -0x4(%rcx,%rbx,1),%cl
mov    %cl,-0x1(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @ft_get_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 3, i32* %5
%6 = call i64 @malloc(i32 32)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
br label %8
8: ; preds = %16, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %8
19: ; preds = %8
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %27, %19
%25 = load i32, i32* %5
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %3
%35 = load i32, i32* %5
%36 = add nsw i32 %35, -1
store i32 %36, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 %33, i8* %38
br label %24
39: ; preds = %24
%40 = load i8*, i8** %3
ret i8* %40
}

LLVM IR (-O2):
define i8* @ft_get_key(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 32)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ %8, %3 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 10
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = inttoptr i64 %2 to i8*
%11 = getelementptr inbounds i8, i8* %10, i64 3
store i8 0, i8* %11
%12 = shl i64 %4, 32
%13 = ashr exact i64 %12, 32
%14 = add nsw i64 %13, -1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = getelementptr inbounds i8, i8* %10, i64 2
store i8 %16, i8* %17
%18 = add nsw i64 %13, -2
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %20, i8* %21
%22 = add nsw i64 %13, -3
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
store i8 %24, i8* %10
%25 = add nsw i64 %13, -4
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %10, i64 -1
store i8 %27, i8* %28
ret i8* %10
}