#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 */
struct timeval {
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
char *stringpow(char *, int);
int sumofdigits(char *);
int main(void) {
  struct timeval stop, start;
  gettimeofday(&start, NULL);
  char *result;
  int sum;
  result = stringpow("2", 1000);
  sum = sumofdigits(result);
  printf("%d", sum);
  gettimeofday(&stop, NULL);
  printf("\ntook %lu usec\n", stop.tv_usec - start.tv_usec);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
lea    0xe9d(%rip),%rdi
mov    $0x3e8,%esi
call   1050 <stringpow@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <sumofdigits@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x8(%rbp),%esi
sub    -0x10(%rbp),%esi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xea9(%rip),%rdi
mov    $0x3e8,%esi
call   1050 <stringpow@plt>
mov    %rax,%rdi
call   1060 <sumofdigits@plt>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x10(%rsp),%esi
sub    0x8(%rsp),%esi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [2 x i8] c"2\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = call i8* @stringpow(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1000)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @sumofdigits(i8* %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sub nsw i32 %14, %16
%18 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %17)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@.str = [2 x i8] c"2\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"\0Atook %lu usec\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = tail call i8* @stringpow(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1000)
%7 = tail call i32 @sumofdigits(i8* %6)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = sub nsw i32 %11, %13
%15 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %14)
ret i32 0
}