#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 */
scalar_t__ atoi(char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strtok(char *, char *);
long get_t_jiffies(char *cpu_agg) {
  char *cpu_agg_cp = malloc(strlen(cpu_agg) + 1);
  strcpy(cpu_agg_cp, cpu_agg);
  long sum = 0;
  char *token = strtok(cpu_agg_cp, " ");
  while ((token = strtok(NULL, " ")))
    sum += atoi(token);
  free(cpu_agg_cp);
  return sum;
}


x86 assembly (clang, -O0):
<get_t_jiffies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe47(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11e2 <get_t_jiffies+0x82>
mov    -0x20(%rbp),%rdi
call   1080 <atoi@plt>
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ae <get_t_jiffies+0x4e>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_t_jiffies>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe75(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strtok@plt>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
je     11ca <get_t_jiffies+0x6a>
xor    %ebx,%ebx
lea    0xe50(%rip),%r15
mov    %rax,%rdi
call   1080 <atoi@plt>
add    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1070 <strtok@plt>
test   %rax,%rax
jne    11b0 <get_t_jiffies+0x50>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i64 @get_t_jiffies(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = call i8* @malloc(i64 %8)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = call i32 @strcpy(i8* %10, i8* %11)
store i64 0, i64* %4
%13 = load i8*, i8** %3
%14 = call i8* @strtok(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %5
br label %15
15: ; preds = %18, %1
%16 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = call i64 @atoi(i8* %19)
%21 = load i64, i64* %4
%22 = add nsw i64 %21, %20
store i64 %22, i64* %4
br label %15
23: ; preds = %15
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i64, i64* %4
ret i64 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i64 @get_t_jiffies(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = tail call i32 @strcpy(i8* %4, i8* %0)
%6 = tail call i8* @strtok(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %1, %9
%10 = phi i8* [ %14, %9 ], [ %7, %1 ]
%11 = phi i64 [ %13, %9 ], [ 0, %1 ]
%12 = tail call i64 @atoi(i8* %10)
%13 = add nsw i64 %12, %11
%14 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %9
16: ; preds = %9, %1
%17 = phi i64 [ 0, %1 ], [ %13, %9 ]
%18 = tail call i32 @free(i8* %4)
ret i64 %17
}