#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*/ abs(int);
int atoi(char *);
scalar_t__ floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strcmp(char *, char *);
char *strdup(char *);
int strlen(char *);
char *strtok(char *, char *);
char *format_message_package(char *operation) {
  int i = 0;
  char *op;
  char *val1;
  char *val2;
  char *p;
  for (p = strtok(operation, " "); p != NULL; p = strtok(NULL, " ")) {
    if (i == 0) {
      val1 = strdup(p);
    } else if (i == 1) {
      op = strdup(p);
    } else if (i == 2) {
      val2 = strdup(p);
    }
    i++;
  }
  int a = atoi(val1);
  int b = atoi(val2);
  int a_size = a == 0 ? 1 : (int)floor(log10(abs(a))) + 1;
  int b_size = b == 0 ? 1 : (int)floor(log10(abs(b))) + 1;
  int total_size = a_size + b_size + strlen(op) + 3;
  char *buf = malloc(sizeof(char) * total_size);
  if (!strcmp(op, "+")) {
    sprintf(buf, "add %d %d", a, b);
  } else if (!strcmp(op, "-")) {
    sprintf(buf, "sub %d %d", a, b);
  } else if (!strcmp(op, "*")) {
    sprintf(buf, "mul %d %d", a, b);
  } else if (!strcmp(op, "/")) {
    sprintf(buf, "div %d %d", a, b);
  }
  return buf;
}


x86 assembly (clang, -O0):
<format_message_package>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     124d <format_message_package+0xad>
cmpl   $0x0,-0xc(%rbp)
jne    11ee <format_message_package+0x4e>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    122b <format_message_package+0x8b>
cmpl   $0x1,-0xc(%rbp)
jne    120a <format_message_package+0x6a>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    1226 <format_message_package+0x86>
cmpl   $0x2,-0xc(%rbp)
jne    1221 <format_message_package+0x81>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1226 <format_message_package+0x86>
jmp    122b <format_message_package+0x8b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc1(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11c7 <format_message_package+0x27>
mov    -0x20(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    127c <format_message_package+0xdc>
mov    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1298 <format_message_package+0xf8>
mov    -0x34(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%edi
call   1080 <log10@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    12b5 <format_message_package+0x115>
mov    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    12d1 <format_message_package+0x131>
mov    -0x38(%rbp),%edi
call   1030 <abs@plt>
mov    %eax,%edi
call   1080 <log10@plt>
mov    %eax,%edi
call   10c0 <floor@plt>
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x3c(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
add    %ecx,%eax
add    $0x3,%eax
mov    %eax,-0x44(%rbp)
movslq -0x44(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xcee(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    133d <format_message_package+0x19d>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xcd1(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    13e3 <format_message_package+0x243>
mov    -0x18(%rbp),%rdi
lea    0xcc6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1371 <format_message_package+0x1d1>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xca9(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    13de <format_message_package+0x23e>
mov    -0x18(%rbp),%rdi
lea    0xc9e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    13a5 <format_message_package+0x205>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xc81(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    13d9 <format_message_package+0x239>
mov    -0x18(%rbp),%rdi
lea    0xc76(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    13d4 <format_message_package+0x234>
mov    -0x50(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
lea    0xc59(%rip),%rsi
call   10a0 <sprintf@plt>
jmp    13d9 <format_message_package+0x239>
jmp    13de <format_message_package+0x23e>
jmp    13e3 <format_message_package+0x243>
mov    -0x50(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_message_package>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe61(%rip),%rbp
mov    %rbp,%rsi
call   1060 <strtok@plt>
xor    %ebx,%ebx
jmp    11cd <format_message_package+0x3d>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r12
add    $0x1,%ebx
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11fd <format_message_package+0x6d>
cmp    $0x2,%ebx
je     11b0 <format_message_package+0x20>
cmp    $0x1,%ebx
je     11f0 <format_message_package+0x60>
test   %ebx,%ebx
jne    11bb <format_message_package+0x2b>
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r14
jmp    11bb <format_message_package+0x2b>
nopl   0x0(%rax,%rax,1)
mov    %rax,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r15
jmp    11bb <format_message_package+0x2b>
mov    %r14,%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
test   %r14d,%r14d
je     124e <format_message_package+0xbe>
mov    %r14d,%edi
neg    %edi
cmovs  %r14d,%edi
call   1070 <log10@plt>
mov    %eax,%edi
call   10b0 <floor@plt>
mov    %rax,%rbx
add    $0x4,%ebx
test   %ebp,%ebp
je     1257 <format_message_package+0xc7>
mov    %ebp,%edi
neg    %edi
cmovs  %ebp,%edi
call   1070 <log10@plt>
mov    %eax,%edi
call   10b0 <floor@plt>
add    $0x1,%eax
jmp    125c <format_message_package+0xcc>
mov    $0x4,%ebx
test   %ebp,%ebp
jne    1236 <format_message_package+0xa6>
mov    $0x1,%eax
add    %eax,%ebx
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xd89(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     12c7 <format_message_package+0x137>
lea    0xd82(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     12d0 <format_message_package+0x140>
lea    0xd7b(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     12d9 <format_message_package+0x149>
lea    0xd74(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
jne    12ed <format_message_package+0x15d>
lea    0xd63(%rip),%rsi
jmp    12e0 <format_message_package+0x150>
lea    0xd36(%rip),%rsi
jmp    12e0 <format_message_package+0x150>
lea    0xd39(%rip),%rsi
jmp    12e0 <format_message_package+0x150>
lea    0xd3c(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
mov    %ebp,%ecx
call   1090 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [10 x i8] c"add %d %d\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [10 x i8] c"sub %d %d\00"
@.str.5 = [2 x i8] c"*\00"
@.str.6 = [10 x i8] c"mul %d %d\00"
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [10 x i8] c"div %d %d\00"
define i8* @format_message_package(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%14 = load i8*, i8** %2
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %7
br label %16
16: ; preds = %42, %1
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %7
%24 = call i8* @strdup(i8* %23)
store i8* %24, i8** %5
br label %39
25: ; preds = %19
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %7
%30 = call i8* @strdup(i8* %29)
store i8* %30, i8** %4
br label %38
31: ; preds = %25
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 2
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %6
br label %37
37: ; preds = %34, %31
br label %38
38: ; preds = %37, %28
br label %39
39: ; preds = %38, %22
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %42
42: ; preds = %39
%43 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %43, i8** %7
br label %16
44: ; preds = %16
%45 = load i8*, i8** %5
%46 = call i32 @atoi(i8* %45)
store i32 %46, i32* %8
%47 = load i8*, i8** %6
%48 = call i32 @atoi(i8* %47)
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %44
br label %59
52: ; preds = %44
%53 = load i32, i32* %8
%54 = call i32 @abs(i32 %53)
%55 = call i32 @log10(i32 %54)
%56 = call i64 @floor(i32 %55)
%57 = trunc i64 %56 to i32
%58 = add nsw i32 %57, 1
br label %59
59: ; preds = %52, %51
%60 = phi i32 [ 1, %51 ], [ %58, %52 ]
store i32 %60, i32* %10
%61 = load i32, i32* %9
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %59
br label %71
64: ; preds = %59
%65 = load i32, i32* %9
%66 = call i32 @abs(i32 %65)
%67 = call i32 @log10(i32 %66)
%68 = call i64 @floor(i32 %67)
%69 = trunc i64 %68 to i32
%70 = add nsw i32 %69, 1
br label %71
71: ; preds = %64, %63
%72 = phi i32 [ 1, %63 ], [ %70, %64 ]
store i32 %72, i32* %11
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = add nsw i32 %73, %74
%76 = load i8*, i8** %4
%77 = call i32 @strlen(i8* %76)
%78 = add nsw i32 %75, %77
%79 = add nsw i32 %78, 3
store i32 %79, i32* %12
%80 = load i32, i32* %12
%81 = sext i32 %80 to i64
%82 = mul i64 1, %81
%83 = trunc i64 %82 to i32
%84 = call i8* @malloc(i32 %83)
store i8* %84, i8** %13
%85 = load i8*, i8** %4
%86 = call i32 @strcmp(i8* %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%87 = icmp ne i32 %86, 0
br i1 %87, label %93, label %88
88: ; preds = %71
%89 = load i8*, i8** %13
%90 = load i32, i32* %8
%91 = load i32, i32* %9
%92 = call i32 @sprintf(i8* %89, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %90, i32 %91)
br label %123
93: ; preds = %71
%94 = load i8*, i8** %4
%95 = call i32 @strcmp(i8* %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%96 = icmp ne i32 %95, 0
br i1 %96, label %102, label %97
97: ; preds = %93
%98 = load i8*, i8** %13
%99 = load i32, i32* %8
%100 = load i32, i32* %9
%101 = call i32 @sprintf(i8* %98, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %99, i32 %100)
br label %122
102: ; preds = %93
%103 = load i8*, i8** %4
%104 = call i32 @strcmp(i8* %103, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%105 = icmp ne i32 %104, 0
br i1 %105, label %111, label %106
106: ; preds = %102
%107 = load i8*, i8** %13
%108 = load i32, i32* %8
%109 = load i32, i32* %9
%110 = call i32 @sprintf(i8* %107, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %108, i32 %109)
br label %121
111: ; preds = %102
%112 = load i8*, i8** %4
%113 = call i32 @strcmp(i8* %112, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%114 = icmp ne i32 %113, 0
br i1 %114, label %120, label %115
115: ; preds = %111
%116 = load i8*, i8** %13
%117 = load i32, i32* %8
%118 = load i32, i32* %9
%119 = call i32 @sprintf(i8* %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %117, i32 %118)
br label %120
120: ; preds = %115, %111
br label %121
121: ; preds = %120, %106
br label %122
122: ; preds = %121, %97
br label %123
123: ; preds = %122, %88
%124 = load i8*, i8** %13
ret i8* %124
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [10 x i8] c"add %d %d\00"
@.str.3 = [2 x i8] c"-\00"
@.str.4 = [10 x i8] c"sub %d %d\00"
@.str.5 = [2 x i8] c"*\00"
@.str.6 = [10 x i8] c"mul %d %d\00"
@.str.7 = [2 x i8] c"/\00"
@.str.8 = [10 x i8] c"div %d %d\00"
define noalias i8* @format_message_package(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, %16
%5 = phi i32 [ %20, %16 ], [ 0, %1 ]
%6 = phi i8* [ %19, %16 ], [ undef, %1 ]
%7 = phi i8* [ %18, %16 ], [ undef, %1 ]
%8 = phi i8* [ %17, %16 ], [ undef, %1 ]
%9 = phi i8* [ %21, %16 ], [ %2, %1 ]
switch i32 %5, label %16 [
i32 0, label %10
i32 1, label %12
i32 2, label %14
]
10: ; preds = %4
%11 = tail call i8* @strdup(i8* %9)
br label %16
12: ; preds = %4
%13 = tail call i8* @strdup(i8* %9)
br label %16
14: ; preds = %4
%15 = tail call i8* @strdup(i8* %9)
br label %16
16: ; preds = %4, %12, %14, %10
%17 = phi i8* [ %8, %10 ], [ %8, %12 ], [ %15, %14 ], [ %8, %4 ]
%18 = phi i8* [ %11, %10 ], [ %7, %12 ], [ %7, %14 ], [ %7, %4 ]
%19 = phi i8* [ %6, %10 ], [ %13, %12 ], [ %6, %14 ], [ %6, %4 ]
%20 = add nuw nsw i32 %5, 1
%21 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %4
23: ; preds = %16
%24 = tail call i32 @atoi(i8* %18)
%25 = tail call i32 @atoi(i8* %17)
%26 = icmp eq i32 %24, 0
br i1 %26, label %33, label %27
27: ; preds = %23
%28 = tail call i32 @llvm.abs.i32(i32 %24, i1 true)
%29 = tail call i32 @log10(i32 %28)
%30 = tail call i64 @floor(i32 %29)
%31 = trunc i64 %30 to i32
%32 = add i32 %31, 4
br label %33
33: ; preds = %23, %27
%34 = phi i32 [ %32, %27 ], [ 4, %23 ]
%35 = icmp eq i32 %25, 0
br i1 %35, label %42, label %36
36: ; preds = %33
%37 = tail call i32 @llvm.abs.i32(i32 %25, i1 true)
%38 = tail call i32 @log10(i32 %37)
%39 = tail call i64 @floor(i32 %38)
%40 = trunc i64 %39 to i32
%41 = add nsw i32 %40, 1
br label %42
42: ; preds = %33, %36
%43 = phi i32 [ %41, %36 ], [ 1, %33 ]
%44 = tail call i32 @strlen(i8* %19)
%45 = add i32 %34, %43
%46 = add i32 %45, %44
%47 = tail call i8* @malloc(i32 %46)
%48 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%49 = icmp eq i32 %48, 0
br i1 %49, label %59, label %50
50: ; preds = %42
%51 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp eq i32 %51, 0
br i1 %52, label %59, label %53
53: ; preds = %50
%54 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%55 = icmp eq i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = tail call i32 @strcmp(i8* dereferenceable(1) %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56, %53, %50, %42
%60 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %42 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %50 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), %53 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), %56 ]
%61 = tail call i32 @sprintf(i8* dereferenceable(1) %47, i8* dereferenceable(1) %60, i32 %24, i32 %25)
br label %62
62: ; preds = %59, %56
ret i8* %47
}