#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 */
char *malloc(int);
int /*<<< orphan*/ sscanf(char *, char *, char *, char *, char *);
char *mots(char *str, int idx) {
  char *mot1 = malloc(sizeof(char) * 50);
  char *mot2 = malloc(sizeof(char) * 50);
  char *mot3 = malloc(sizeof(char) * 50);
  sscanf(str, "%s %s %s", mot1, mot2, mot3);
  if (idx == 0)
    return mot1;
  else if (idx == 1)
    return mot2;
  else if (idx == 2)
    return mot3;
  return mot3;
}


x86 assembly (clang, -O0):
<mots>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    0xe90(%rip),%rsi
call   1040 <sscanf@plt>
cmpl   $0x0,-0x14(%rbp)
jne    118c <mots+0x6c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <mots+0xac>
cmpl   $0x1,-0x14(%rbp)
jne    11a3 <mots+0x83>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <mots+0xac>
cmpl   $0x2,-0x14(%rbp)
jne    11ba <mots+0x9a>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cc <mots+0xac>
jmp    11bf <mots+0x9f>
jmp    11c4 <mots+0xa4>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mots>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r12
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,%r15
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0x32,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
lea    0xea5(%rip),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1040 <sscanf@plt>
test   %ebp,%ebp
je     117f <mots+0x5f>
cmp    $0x2,%ebp
je     117a <mots+0x5a>
cmp    $0x1,%ebp
je     1182 <mots+0x62>
mov    %r14,%rbx
jmp    1182 <mots+0x62>
mov    %r15,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s %s %s\00"
define i8* @mots(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = call i8* @malloc(i32 50)
store i8* %9, i8** %6
%10 = call i8* @malloc(i32 50)
store i8* %10, i8** %7
%11 = call i8* @malloc(i32 50)
store i8* %11, i8** %8
%12 = load i8*, i8** %4
%13 = load i8*, i8** %6
%14 = load i8*, i8** %7
%15 = load i8*, i8** %8
%16 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %14, i8* %15)
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = load i8*, i8** %6
store i8* %20, i8** %3
br label %35
21: ; preds = %2
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = load i8*, i8** %7
store i8* %25, i8** %3
br label %35
26: ; preds = %21
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = load i8*, i8** %8
store i8* %30, i8** %3
br label %35
31: ; preds = %26
br label %32
32: ; preds = %31
br label %33
33: ; preds = %32
%34 = load i8*, i8** %8
store i8* %34, i8** %3
br label %35
35: ; preds = %33, %29, %24, %19
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s %s %s\00"
define i8* @mots(i8* nocapture %0, i32 %1) {
%3 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%4 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%5 = tail call dereferenceable_or_null(50) i8* @malloc(i32 50)
%6 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4, i8* %5)
switch i32 %1, label %9 [
i32 0, label %10
i32 1, label %7
i32 2, label %8
]
7: ; preds = %2
br label %10
8: ; preds = %2
br label %10
9: ; preds = %2
br label %10
10: ; preds = %2, %9, %8, %7
%11 = phi i8* [ %4, %7 ], [ %5, %8 ], [ %5, %9 ], [ %3, %2 ]
ret i8* %11
}