#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*/ log_debug(char *);
int tokenize_add_append(char **h_msg, char **h_file_name, int *p_file_size) {
  char *scanner, *msg;
  msg = *h_msg;
  log_debug("Tokenizing Add/Append command");
  scanner = msg;
  while (*scanner != ' ') {
    if (*scanner == '\0') {
      return 1;
    }
    scanner++;
  }
  if (*scanner == '\0') {
    return 1;
  }
  *scanner = '\0';
  scanner++;
  if (*scanner == '\0') {
    return 1;
  }
  log_debug("Successfully tokenized first part of message");
  log_debug(scanner);
  *h_file_name = scanner;
  while (*scanner != ' ') {
    if (*scanner == '\0') {
      return 1;
    }
    scanner++;
  }
  *scanner = '\0';
  scanner++;
  if (*scanner == '\0') {
    return 1;
  }
  log_debug("Successfully tokenized second part of message");
  log_debug(scanner);
  *p_file_size = atoi(scanner);
  log_debug("Successfully converted message length to integer");
  return 0;
}


x86 assembly (clang, -O0):
<tokenize_add_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <log_debug@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1190 <tokenize_add_append+0x70>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117f <tokenize_add_append+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <tokenize_add_append+0x180>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1153 <tokenize_add_append+0x33>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11ac <tokenize_add_append+0x8c>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <tokenize_add_append+0x180>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11db <tokenize_add_append+0xbb>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <tokenize_add_append+0x180>
lea    0xe3c(%rip),%rdi
call   1030 <log_debug@plt>
mov    -0x28(%rbp),%rdi
call   1030 <log_debug@plt>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     1238 <tokenize_add_append+0x118>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1227 <tokenize_add_append+0x107>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <tokenize_add_append+0x180>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11fb <tokenize_add_append+0xdb>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1267 <tokenize_add_append+0x147>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <tokenize_add_append+0x180>
lea    0xddd(%rip),%rdi
call   1030 <log_debug@plt>
mov    -0x28(%rbp),%rdi
call   1030 <log_debug@plt>
mov    -0x28(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    0xde5(%rip),%rdi
call   1030 <log_debug@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tokenize_add_append>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    (%rdi),%rbp
lea    0xec8(%rip),%rdi
call   1030 <log_debug@plt>
nopl   (%rax)
add    $0x1,%rbp
movzbl -0x1(%rbp),%eax
test   %al,%al
je     1192 <tokenize_add_append+0x72>
cmp    $0x20,%al
jne    1140 <tokenize_add_append+0x20>
movb   $0x0,-0x1(%rbp)
cmpb   $0x0,0x0(%rbp)
mov    $0x1,%r12d
je     1198 <tokenize_add_append+0x78>
lea    0x1(%rbp),%rbx
lea    0xeb3(%rip),%rdi
call   1030 <log_debug@plt>
mov    %rbp,%rdi
call   1030 <log_debug@plt>
mov    %rbp,(%r15)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%eax
test   %al,%al
je     1198 <tokenize_add_append+0x78>
cmp    $0x20,%al
je     11a4 <tokenize_add_append+0x84>
add    $0x1,%rbx
jmp    1180 <tokenize_add_append+0x60>
mov    $0x1,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,-0x1(%rbx)
cmpb   $0x0,(%rbx)
je     1198 <tokenize_add_append+0x78>
lea    0xe97(%rip),%rdi
call   1030 <log_debug@plt>
mov    %rbx,%rdi
call   1030 <log_debug@plt>
mov    %rbx,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
lea    0xea6(%rip),%rdi
call   1030 <log_debug@plt>
xor    %r12d,%r12d
jmp    1198 <tokenize_add_append+0x78>

LLVM IR (-O0):
@.str = [30 x i8] c"Tokenizing Add/Append command\00"
@.str.1 = [45 x i8] c"Successfully tokenized first part of message\00"
@.str.2 = [46 x i8] c"Successfully tokenized second part of message\00"
@.str.3 = [49 x i8] c"Successfully converted message length to integer\00"
define i32 @tokenize_add_append(i8** %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
store i8** %0, i8*** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%10 = load i8**, i8*** %5
%11 = load i8*, i8** %10
store i8* %11, i8** %9
%12 = call i32 @log_debug(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %9
store i8* %13, i8** %8
br label %14
14: ; preds = %25, %3
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 32
br i1 %18, label %19, label %28
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %4
br label %80
25: ; preds = %19
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %8
br label %14
28: ; preds = %14
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %4
br label %80
34: ; preds = %28
%35 = load i8*, i8** %8
store i8 0, i8* %35
%36 = load i8*, i8** %8
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %8
%38 = load i8*, i8** %8
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %34
store i32 1, i32* %4
br label %80
43: ; preds = %34
%44 = call i32 @log_debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%45 = load i8*, i8** %8
%46 = call i32 @log_debug(i8* %45)
%47 = load i8*, i8** %8
%48 = load i8**, i8*** %6
store i8* %47, i8** %48
br label %49
49: ; preds = %60, %43
%50 = load i8*, i8** %8
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 32
br i1 %53, label %54, label %63
54: ; preds = %49
%55 = load i8*, i8** %8
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 1, i32* %4
br label %80
60: ; preds = %54
%61 = load i8*, i8** %8
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %8
br label %49
63: ; preds = %49
%64 = load i8*, i8** %8
store i8 0, i8* %64
%65 = load i8*, i8** %8
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %8
%67 = load i8*, i8** %8
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %63
store i32 1, i32* %4
br label %80
72: ; preds = %63
%73 = call i32 @log_debug(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%74 = load i8*, i8** %8
%75 = call i32 @log_debug(i8* %74)
%76 = load i8*, i8** %8
%77 = call i32 @atoi(i8* %76)
%78 = load i32*, i32** %7
store i32 %77, i32* %78
%79 = call i32 @log_debug(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %80
80: ; preds = %72, %71, %59, %42, %33, %24
%81 = load i32, i32* %4
ret i32 %81
}

LLVM IR (-O2):
@.str = [30 x i8] c"Tokenizing Add/Append command\00"
@.str.1 = [45 x i8] c"Successfully tokenized first part of message\00"
@.str.2 = [46 x i8] c"Successfully tokenized second part of message\00"
@.str.3 = [49 x i8] c"Successfully converted message length to integer\00"
define i32 @tokenize_add_append(i8** nocapture %0, i8** nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = load i8*, i8** %0
%5 = tail call i32 @log_debug(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %9, %3
%7 = phi i8* [ %4, %3 ], [ %10, %9 ]
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 32, label %11
i8 0, label %32
]
9: ; preds = %6
%10 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
11: ; preds = %6
store i8 0, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %32, label %15
15: ; preds = %11
%16 = tail call i32 @log_debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @log_debug(i8* %12)
store i8* %12, i8** %1
br label %18
18: ; preds = %21, %15
%19 = phi i8* [ %12, %15 ], [ %22, %21 ]
%20 = load i8, i8* %19
switch i8 %20, label %21 [
i8 32, label %23
i8 0, label %32
]
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %19, i64 1
br label %18
23: ; preds = %18
store i8 0, i8* %19
%24 = getelementptr inbounds i8, i8* %19, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = tail call i32 @log_debug(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @log_debug(i8* %24)
%30 = tail call i32 @atoi(i8* %24)
store i32 %30, i32* %2
%31 = tail call i32 @log_debug(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %6, %18, %23, %11, %27
%33 = phi i32 [ 0, %27 ], [ 1, %11 ], [ 1, %23 ], [ 1, %18 ], [ 1, %6 ]
ret i32 %33
}