#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_w_jiffies(char *cpu_agg) {
  char *cpu_agg_cp = malloc(strlen(cpu_agg) + 1);
  strcpy(cpu_agg_cp, cpu_agg);
  int i;
  long sum = 0;
  char *token = strtok(cpu_agg_cp, " ");
  for (i = 0; i < 3 && (token = strtok(NULL, " ")); i++)
    sum += atoi(token);
  free(cpu_agg_cp);
  return sum;
}


x86 assembly (clang, -O0):
<get_w_jiffies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x14(%rbp)
mov    %al,-0x29(%rbp)
jge    11e2 <get_w_jiffies+0x82>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe31(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f2 <get_w_jiffies+0x92>
jmp    1211 <get_w_jiffies+0xb1>
mov    -0x28(%rbp),%rdi
call   1080 <atoi@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b5 <get_w_jiffies+0x55>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_w_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     11f6 <get_w_jiffies+0x96>
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %rax,%r15
lea    0xe47(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
test   %rax,%rax
je     11f3 <get_w_jiffies+0x93>
mov    %rax,%rdi
call   1080 <atoi@plt>
mov    %rax,%rbx
add    %r15,%rbx
lea    0xe26(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
test   %rax,%rax
je     11f6 <get_w_jiffies+0x96>
mov    %rax,%rdi
call   1080 <atoi@plt>
add    %rax,%rbx
jmp    11f6 <get_w_jiffies+0x96>
mov    %r15,%rbx
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_w_jiffies(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 1
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %11, i8* %12)
store i64 0, i64* %5
%14 = load i8*, i8** %3
%15 = call i8* @strtok(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %6
store i32 0, i32* %4
br label %16
16: ; preds = %29, %1
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %20, i8** %6
%21 = icmp ne i8* %20, null
br label %22
22: ; preds = %19, %16
%23 = phi i1 [ false, %16 ], [ %21, %19 ]
br i1 %23, label %24, label %32
24: ; preds = %22
%25 = load i8*, i8** %6
%26 = call i64 @atoi(i8* %25)
%27 = load i64, i64* %5
%28 = add nsw i64 %27, %26
store i64 %28, i64* %5
br label %29
29: ; preds = %24
%30 = load i32, i32* %4
%31 = add nsw i32 %30, 1
store i32 %31, i32* %4
br label %16
32: ; preds = %22
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
%35 = load i64, i64* %5
ret i64 %35
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i64 @get_w_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 %21, label %9
9: ; preds = %1
%10 = tail call i64 @atoi(i8* %7)
%11 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = tail call i64 @atoi(i8* %11)
%15 = add nsw i64 %14, %10
%16 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = tail call i64 @atoi(i8* %16)
%20 = add nsw i64 %19, %15
br label %21
21: ; preds = %18, %13, %9, %1
%22 = phi i64 [ 0, %1 ], [ %10, %9 ], [ %15, %13 ], [ %20, %18 ]
%23 = tail call i32 @free(i8* %4)
ret i64 %22
}