#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 atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int string_mult(char *string) {
  int number1, len;
  char *multpos = NULL;
  char *tempchar;
  multpos = strchr(string, '*');
  if (multpos == NULL)
    return atoi(string);
  len = multpos - string;
  tempchar = malloc(sizeof(char) * (len + 1));
  strncpy(tempchar, string, len);
  tempchar[len] = '\0';
  number1 = atoi(tempchar);
  free(tempchar);
  if (strchr(multpos + 1, '*') != NULL)
    return number1 * string_mult(multpos + 1);
  return number1 * atoi(multpos + 1);
}


x86 assembly (clang, -O0):
<string_mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a2 <string_mult+0x42>
mov    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    1255 <string_mult+0xf5>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2a,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1237 <string_mult+0xd7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <string_mult@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1255 <string_mult+0xf5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_mult>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    $0x2a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ef <string_mult+0x9f>
mov    %rax,%r15
mov    $0x1,%r14d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rbp
sub    %rbx,%rbp
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r15,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1201 <string_mult+0xb1>
imul   %r14d,%ebp
mov    %rbx,%rdi
mov    $0x2a,%esi
call   1050 <strchr@plt>
mov    %rax,%r15
mov    %ebp,%r14d
test   %rax,%rax
jne    1180 <string_mult+0x30>
jmp    11f4 <string_mult+0xa4>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %ebp,%r14d
jmp    120c <string_mult+0xbc>
mov    %rbx,%rdi
call   1070 <atoi@plt>
imul   %ebp,%eax
imul   %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_mult(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %3
store i8* null, i8** %6
%8 = load i8*, i8** %3
%9 = call i8* @strchr(i8* %8, i8 signext 42)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %2
br label %56
15: ; preds = %1
%16 = load i8*, i8** %6
%17 = load i8*, i8** %3
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = mul i64 1, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = call i32 @strncpy(i8* %28, i8* %29, i32 %30)
%32 = load i8*, i8** %7
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %7
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %4
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %6
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i8* @strchr(i8* %41, i8 signext 42)
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %50
44: ; preds = %15
%45 = load i32, i32* %4
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 1
%48 = call i32 @string_mult(i8* %47)
%49 = mul nsw i32 %45, %48
store i32 %49, i32* %2
br label %56
50: ; preds = %15
%51 = load i32, i32* %4
%52 = load i8*, i8** %6
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i32 @atoi(i8* %53)
%55 = mul nsw i32 %51, %54
store i32 %55, i32* %2
br label %56
56: ; preds = %50, %44, %12
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
define i32 @string_mult(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 42)
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %8
4: ; preds = %27, %1
%5 = phi i32 [ 1, %1 ], [ %28, %27 ]
%6 = phi i8* [ %0, %1 ], [ %24, %27 ]
%7 = tail call i32 @atoi(i8* %6)
br label %34
8: ; preds = %1, %27
%9 = phi i8* [ %29, %27 ], [ %2, %1 ]
%10 = phi i8* [ %24, %27 ], [ %0, %1 ]
%11 = phi i32 [ %28, %27 ], [ 1, %1 ]
%12 = ptrtoint i8* %9 to i64
%13 = ptrtoint i8* %10 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = add nsw i32 %15, 1
%17 = tail call i8* @malloc(i32 %16)
%18 = tail call i32 @strncpy(i8* %17, i8* %10, i32 %15)
%19 = shl i64 %14, 32
%20 = ashr exact i64 %19, 32
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 0, i8* %21
%22 = tail call i32 @atoi(i8* %17)
%23 = tail call i32 @free(i8* %17)
%24 = getelementptr inbounds i8, i8* %9, i64 1
%25 = tail call i8* @strchr(i8* %24, i8 signext 42)
%26 = icmp eq i8* %25, null
br i1 %26, label %31, label %27
27: ; preds = %8
%28 = mul nsw i32 %22, %11
%29 = tail call i8* @strchr(i8* dereferenceable(1) %24, i8 signext 42)
%30 = icmp eq i8* %29, null
br i1 %30, label %4, label %8
31: ; preds = %8
%32 = tail call i32 @atoi(i8* %24)
%33 = mul nsw i32 %32, %22
br label %34
34: ; preds = %31, %4
%35 = phi i32 [ %5, %4 ], [ %11, %31 ]
%36 = phi i32 [ %7, %4 ], [ %33, %31 ]
%37 = mul nsw i32 %36, %35
ret i32 %37
}