#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtok_r(char *, char *, char **);
void parse_request(char *buffer, char **method, char **uri) {
  char *copy_buffer;
  char *token, *strtok_saveptr;
  copy_buffer = malloc(strlen(buffer) * sizeof(char) + 1);
  strcpy(copy_buffer, buffer);
  token = strtok_r(copy_buffer, " ", &strtok_saveptr);
  if (!token) {
    *method = 0;
    *uri = 0;
    return;
  }
  *method = malloc(strlen(token) * sizeof(char) + 1);
  strcpy(*method, token);
  token = strtok_r(NULL, " ", &strtok_saveptr);
  if (!token) {
    *method = 0;
    *uri = 0;
    return;
  }
  *uri = malloc(strlen(token) * sizeof(char) + 1);
  strcpy(*uri, token);
  free(copy_buffer);
}


x86 assembly (clang, -O0):
<parse_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe66(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cd <parse_request+0x7d>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    127c <parse_request+0x12c>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf4(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    123f <parse_request+0xef>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    127c <parse_request+0x12c>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_request>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe7d(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     11f5 <parse_request+0xa5>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xe45(%rip),%rsi
mov    %rsp,%rdx
xor    %edi,%edi
call   1060 <strtok_r@plt>
test   %rax,%rax
je     11f5 <parse_request+0xa5>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1030 <free@plt>
jmp    1203 <parse_request+0xb3>
movq   $0x0,(%r15)
movq   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @parse_request(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = add i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = load i8*, i8** %4
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = load i8*, i8** %7
%21 = call i8* @strtok_r(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %21, i8** %8
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %27, label %24
24: ; preds = %3
%25 = load i8**, i8*** %5
store i8* null, i8** %25
%26 = load i8**, i8*** %6
store i8* null, i8** %26
br label %61
27: ; preds = %3
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 1
%32 = add i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
%35 = load i8**, i8*** %5
store i8* %34, i8** %35
%36 = load i8**, i8*** %5
%37 = load i8*, i8** %36
%38 = load i8*, i8** %8
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %9)
store i8* %40, i8** %8
%41 = load i8*, i8** %8
%42 = icmp ne i8* %41, null
br i1 %42, label %46, label %43
43: ; preds = %27
%44 = load i8**, i8*** %5
store i8* null, i8** %44
%45 = load i8**, i8*** %6
store i8* null, i8** %45
br label %61
46: ; preds = %27
%47 = load i8*, i8** %8
%48 = call i32 @strlen(i8* %47)
%49 = sext i32 %48 to i64
%50 = mul i64 %49, 1
%51 = add i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = call i8* @malloc(i32 %52)
%54 = load i8**, i8*** %6
store i8* %53, i8** %54
%55 = load i8**, i8*** %6
%56 = load i8*, i8** %55
%57 = load i8*, i8** %8
%58 = call i32 @strcpy(i8* %56, i8* %57)
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
br label %61
61: ; preds = %46, %43, %24
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @parse_request(i8* %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = add i32 %6, 1
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @strcpy(i8* %8, i8* %0)
%10 = call i8* @strtok_r(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* null, i8** %1
store i8* null, i8** %2
br label %27
13: ; preds = %3
%14 = call i32 @strlen(i8* %10)
%15 = add i32 %14, 1
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %1
%17 = call i32 @strcpy(i8* %16, i8* %10)
%18 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %4)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %13
store i8* null, i8** %1
store i8* null, i8** %2
br label %27
21: ; preds = %13
%22 = call i32 @strlen(i8* %18)
%23 = add i32 %22, 1
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %2
%25 = call i32 @strcpy(i8* %24, i8* %18)
%26 = call i32 @free(i8* %8)
br label %27
27: ; preds = %21, %20, %12
ret void
}