#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 command {
  int dummy;
};

/* Variables and functions */
scalar_t__ command_append(struct command *, char *);
int /*<<< orphan*/ command_execute(struct command *);
int /*<<< orphan*/ command_free(struct command *);
struct command *command_new();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strtok_r(char *, char *, char **);
void execute(char *buf) {
  struct command *cmd = command_new();
  char *arg;
  char *rest;
  if (!cmd) {
    fprintf(stderr, "Memory exhausted\n");
    return;
  }
  while (*buf && *buf == ' ')
    buf++;
  if (!*buf) {
    command_free(cmd);
    return;
  }
  arg = strtok_r(buf, " ", &rest);
  while (arg) {
    if (command_append(cmd, arg) < 0) {
      command_free(cmd);
      fprintf(stderr, "Memory exhausted\n");
      return;
    }
    while (*rest && *rest == ' ')
      rest++;
    arg = strtok_r(NULL, " ", &rest);
  }
  command_append(cmd, NULL);
  command_execute(cmd);
  command_free(cmd);
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <command_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119c <execute+0x3c>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12e6 <execute+0x186>
jmp    11a1 <execute+0x41>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     11c6 <execute+0x66>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11d6 <execute+0x76>
jmp    11e7 <execute+0x87>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11a1 <execute+0x41>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1202 <execute+0xa2>
mov    -0x10(%rbp),%rdi
call   1080 <command_free@plt>
jmp    12e6 <execute+0x186>
mov    -0x8(%rbp),%rdi
lea    0xe05(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12c7 <execute+0x167>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <command_append@plt>
cmp    $0x0,%rax
jge    125f <execute+0xff>
mov    -0x10(%rbp),%rdi
call   1080 <command_free@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12e6 <execute+0x186>
jmp    1264 <execute+0x104>
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x22(%rbp)
je     1289 <execute+0x129>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1299 <execute+0x139>
jmp    12aa <execute+0x14a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1264 <execute+0x104>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd5d(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x18(%rbp)
jmp    121a <execute+0xba>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <command_append@plt>
mov    -0x10(%rbp),%rdi
call   1030 <command_execute@plt>
mov    -0x10(%rbp),%rdi
call   1080 <command_free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <command_new@plt>
test   %rax,%rax
je     11a4 <execute+0x44>
mov    %rax,%r12
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
cmp    $0x20,%al
jne    118d <execute+0x2d>
add    $0x1,%rbx
jmp    1180 <execute+0x20>
test   %al,%al
jne    11c4 <execute+0x64>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <command_free@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <fprintf@plt>
lea    0xe47(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     122f <execute+0xcf>
lea    0xe30(%rip),%r14
mov    %rsp,%r15
jmp    1202 <execute+0xa2>
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strtok_r@plt>
test   %rax,%rax
je     122f <execute+0xcf>
mov    %r12,%rdi
mov    %rax,%rsi
call   1070 <command_append@plt>
test   %rax,%rax
js     124b <execute+0xeb>
mov    (%rsp),%rax
cmpb   $0x20,(%rax)
jne    11f0 <execute+0x90>
add    $0x1,%rax
nop
mov    %rax,(%rsp)
cmpb   $0x20,(%rax)
lea    0x1(%rax),%rax
je     1220 <execute+0xc0>
jmp    11f0 <execute+0x90>
mov    %r12,%rdi
xor    %esi,%esi
call   1070 <command_append@plt>
mov    %r12,%rdi
call   1030 <command_execute@plt>
mov    %r12,%rdi
call   1080 <command_free@plt>
jmp    1268 <execute+0x108>
mov    %r12,%rdi
call   1080 <command_free@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xd9d(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.command = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Memory exhausted\0A\00"
@.str.1 = [2 x i8] c" \00"
define void @execute(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.command*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call %struct.command* (...) @command_new()
store %struct.command* %6, %struct.command** %3
%7 = load %struct.command*, %struct.command** %3
%8 = icmp ne %struct.command* %7, null
br i1 %8, label %12, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %76
12: ; preds = %1
br label %13
13: ; preds = %25, %12
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 32
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %25, label %28
25: ; preds = %23
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
br label %13
28: ; preds = %23
%29 = load i8*, i8** %2
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load %struct.command*, %struct.command** %3
%34 = call i32 @command_free(%struct.command* %33)
br label %76
35: ; preds = %28
%36 = load i8*, i8** %2
%37 = call i8* @strtok_r(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
store i8* %37, i8** %4
br label %38
38: ; preds = %67, %35
%39 = load i8*, i8** %4
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %69
41: ; preds = %38
%42 = load %struct.command*, %struct.command** %3
%43 = load i8*, i8** %4
%44 = call i64 @command_append(%struct.command* %42, i8* %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = load %struct.command*, %struct.command** %3
%48 = call i32 @command_free(%struct.command* %47)
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %76
51: ; preds = %41
br label %52
52: ; preds = %64, %51
%53 = load i8*, i8** %5
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %52
%58 = load i8*, i8** %5
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 32
br label %62
62: ; preds = %57, %52
%63 = phi i1 [ false, %52 ], [ %61, %57 ]
br i1 %63, label %64, label %67
64: ; preds = %62
%65 = load i8*, i8** %5
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %5
br label %52
67: ; preds = %62
%68 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
store i8* %68, i8** %4
br label %38
69: ; preds = %38
%70 = load %struct.command*, %struct.command** %3
%71 = call i64 @command_append(%struct.command* %70, i8* null)
%72 = load %struct.command*, %struct.command** %3
%73 = call i32 @command_execute(%struct.command* %72)
%74 = load %struct.command*, %struct.command** %3
%75 = call i32 @command_free(%struct.command* %74)
br label %76
76: ; preds = %69, %46, %32, %9
ret void
}

LLVM IR (-O2):
%struct.command = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Memory exhausted\0A\00"
@.str.1 = [2 x i8] c" \00"
define void @execute(i8* %0) {
%2 = alloca i8*
%3 = tail call %struct.command* (...) @command_new()
%4 = bitcast i8** %2 to i8*
%5 = icmp eq %struct.command* %3, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %43
9: ; preds = %1, %12
%10 = phi i8* [ %13, %12 ], [ %0, %1 ]
%11 = load i8, i8* %10
switch i8 %11, label %16 [
i8 32, label %12
i8 0, label %14
]
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
br label %9
14: ; preds = %9
%15 = tail call i32 @command_free(%struct.command* %3)
br label %43
16: ; preds = %9
%17 = call i8* @strtok_r(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2)
%18 = icmp eq i8* %17, null
br i1 %18, label %39, label %19
19: ; preds = %16, %36
%20 = phi i8* [ %37, %36 ], [ %17, %16 ]
%21 = call i64 @command_append(%struct.command* %3, i8* %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 32
br i1 %26, label %31, label %36
27: ; preds = %19
%28 = call i32 @command_free(%struct.command* %3)
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %43
31: ; preds = %23, %31
%32 = phi i8* [ %33, %31 ], [ %24, %23 ]
%33 = getelementptr inbounds i8, i8* %32, i64 1
store i8* %33, i8** %2
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 32
br i1 %35, label %31, label %36
36: ; preds = %31, %23
%37 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %19
39: ; preds = %36, %16
%40 = call i64 @command_append(%struct.command* %3, i8* null)
%41 = call i32 @command_execute(%struct.command* %3)
%42 = call i32 @command_free(%struct.command* %3)
br label %43
43: ; preds = %39, %27, %14, %6
ret void
}