#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*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char *);
int strlen(char *);
char *strtok(char *, char *);
char *get_final_message(char *bufin) {
  char *p;
  int i = 0;
  char *status;
  char *result;
  for (p = strtok(bufin, " "); p != NULL; p = strtok(NULL, " ")) {
    if (i == 0) {
      status = strdup(p);
    } else if (i == 1) {
      result = strdup(p);
    }
    i++;
  }
  char *final_message;
  if (!strcmp(status, "0")) {
    char *message = "Sucesso (0): Resultado =";
    int total_size = strlen(message) + strlen(result) + 2;
    final_message = malloc(total_size * sizeof(char));
    sprintf(final_message, "%s %s", message, result);
  } else if (!strcmp(status, "1")) {
    if (!strcmp(result, "ER1"))
      final_message = "Erro (1): Cod ER1 Divisao por zero";
    else if (!strcmp(result, "ER2"))
      final_message = "Erro (1): Cod ER2 Erro inesperado";
  }
  return final_message;
}


x86 assembly (clang, -O0):
<get_final_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ec <get_final_message+0x8c>
cmpl   $0x0,-0x14(%rbp)
jne    11ae <get_final_message+0x4e>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    11ca <get_final_message+0x6a>
cmpl   $0x1,-0x14(%rbp)
jne    11c5 <get_final_message+0x65>
mov    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    11ca <get_final_message+0x6a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe22(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    1187 <get_final_message+0x27>
mov    -0x20(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1262 <get_final_message+0x102>
lea    0xdf8(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xdc5(%rip),%rsi
call   1070 <sprintf@plt>
jmp    12d7 <get_final_message+0x177>
mov    -0x20(%rbp),%rdi
lea    0xdb8(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12d2 <get_final_message+0x172>
mov    -0x28(%rbp),%rdi
lea    0xd9d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12a4 <get_final_message+0x144>
lea    0xd8c(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    12cd <get_final_message+0x16d>
mov    -0x28(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    12c8 <get_final_message+0x168>
lea    0xd8a(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    12cd <get_final_message+0x16d>
jmp    12d2 <get_final_message+0x172>
jmp    12d7 <get_final_message+0x177>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_final_message>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%r12
mov    %r12,%rsi
call   1060 <strtok@plt>
xor    %ebx,%ebx
jmp    119d <get_final_message+0x3d>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
add    $0x1,%ebx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11b3 <get_final_message+0x53>
cmp    $0x1,%ebx
je     1180 <get_final_message+0x20>
test   %ebx,%ebx
jne    118b <get_final_message+0x2b>
mov    %rax,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
jmp    118b <get_final_message+0x2b>
lea    0xe48(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11fe <get_final_message+0x9e>
lea    0xe58(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    123a <get_final_message+0xda>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
lea    0xe36(%rip),%rax
lea    0xe52(%rip),%rbx
cmove  %rax,%rbx
jmp    123a <get_final_message+0xda>
lea    0xdff(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xdf1(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
call   1070 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [25 x i8] c"Sucesso (0): Resultado =\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.4 = [2 x i8] c"1\00"
@.str.5 = [4 x i8] c"ER1\00"
@.str.6 = [35 x i8] c"Erro (1): Cod ER1 Divisao por zero\00"
@.str.7 = [4 x i8] c"ER2\00"
@.str.8 = [34 x i8] c"Erro (1): Cod ER2 Erro inesperado\00"
define i8* @get_final_message(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%10 = load i8*, i8** %2
%11 = call i8* @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %3
br label %12
12: ; preds = %31, %1
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %33
15: ; preds = %12
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %5
br label %28
21: ; preds = %15
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8*, i8** %3
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %6
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27, %18
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %31
31: ; preds = %28
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %32, i8** %3
br label %12
33: ; preds = %12
%34 = load i8*, i8** %5
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %53, label %37
37: ; preds = %33
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8** %8
%38 = load i8*, i8** %8
%39 = call i32 @strlen(i8* %38)
%40 = load i8*, i8** %6
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %39, %41
%43 = add nsw i32 %42, 2
store i32 %43, i32* %9
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = mul i64 %45, 1
%47 = trunc i64 %46 to i32
%48 = call i8* @malloc(i32 %47)
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = load i8*, i8** %8
%51 = load i8*, i8** %6
%52 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %51)
br label %70
53: ; preds = %33
%54 = load i8*, i8** %5
%55 = call i32 @strcmp(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp ne i32 %55, 0
br i1 %56, label %69, label %57
57: ; preds = %53
%58 = load i8*, i8** %6
%59 = call i32 @strcmp(i8* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %57
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %68
62: ; preds = %57
%63 = load i8*, i8** %6
%64 = call i32 @strcmp(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%65 = icmp ne i32 %64, 0
br i1 %65, label %67, label %66
66: ; preds = %62
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %67
67: ; preds = %66, %62
br label %68
68: ; preds = %67, %61
br label %69
69: ; preds = %68, %53
br label %70
70: ; preds = %69, %37
%71 = load i8*, i8** %7
ret i8* %71
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [25 x i8] c"Sucesso (0): Resultado =\00"
@.str.3 = [6 x i8] c"%s %s\00"
@.str.4 = [2 x i8] c"1\00"
@.str.5 = [4 x i8] c"ER1\00"
@.str.6 = [35 x i8] c"Erro (1): Cod ER1 Divisao por zero\00"
@.str.8 = [34 x i8] c"Erro (1): Cod ER2 Erro inesperado\00"
define i8* @get_final_message(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp ne i8* %2, null
br label %4
4: ; preds = %1, %13
%5 = phi i8* [ %17, %13 ], [ %2, %1 ]
%6 = phi i32 [ %16, %13 ], [ 0, %1 ]
%7 = phi i8* [ %15, %13 ], [ undef, %1 ]
%8 = phi i8* [ %14, %13 ], [ undef, %1 ]
switch i32 %6, label %13 [
i32 0, label %9
i32 1, label %11
]
9: ; preds = %4
%10 = tail call i8* @strdup(i8* %5)
br label %13
11: ; preds = %4
%12 = tail call i8* @strdup(i8* %5)
br label %13
13: ; preds = %4, %11, %9
%14 = phi i8* [ %10, %9 ], [ %8, %11 ], [ %8, %4 ]
%15 = phi i8* [ %7, %9 ], [ %12, %11 ], [ %7, %4 ]
%16 = add nuw nsw i32 %6, 1
%17 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %4
19: ; preds = %13
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %19
%23 = tail call i32 @strlen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @strlen(i8* %15)
%25 = add i32 %23, 2
%26 = add i32 %25, %24
%27 = tail call i8* @malloc(i32 %26)
%28 = tail call i32 @sprintf(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %36
29: ; preds = %19
%30 = tail call i32 @strcmp(i8* dereferenceable(1) %14, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0)
br label %36
36: ; preds = %32, %29, %22
%37 = phi i8* [ undef, %29 ], [ %27, %22 ], [ %35, %32 ]
ret i8* %37
}