#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__ isalnum(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void reverse(char *line) {
  char copy[80];
  char word[80];
  memset(copy, 0, 80);
  int line_len = strlen(line);
  int word_len = 0;
  int i;
  for (i = line_len; i >= 0; --i) {
    if (line[i] == ' ' && word_len > 0) {
      memset(word, 0, 80);
      strncpy(word, line + i + 1, word_len);
      strcat(copy, word);
      strcat(copy, " ");
      word_len = 0;
    } else if (isalnum(line[i]) || line[i] == '\'') {
      word_len++;
    }
  }
  if (word_len > 0) {
    memset(word, 0, 80);
    strncpy(word, line, word_len);
    strcat(copy, word);
  }
  strcpy(line, copy);
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0xb4(%rbp)
movl   $0x0,-0xb8(%rbp)
mov    -0xb4(%rbp),%eax
mov    %eax,-0xbc(%rbp)
cmpl   $0x0,-0xbc(%rbp)
jl     129f <reverse+0x13f>
mov    -0x8(%rbp),%rax
movslq -0xbc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    123c <reverse+0xdc>
cmpl   $0x0,-0xb8(%rbp)
jle    123c <reverse+0xdc>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xbc(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
mov    -0xb8(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x60(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1080 <strcat@plt>
movl   $0x0,-0xb8(%rbp)
jmp    1286 <reverse+0x126>
mov    -0x8(%rbp),%rax
movslq -0xbc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isalnum@plt>
cmp    $0x0,%rax
jne    1272 <reverse+0x112>
mov    -0x8(%rbp),%rax
movslq -0xbc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x27,%eax
jne    1281 <reverse+0x121>
mov    -0xb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb8(%rbp)
jmp    1286 <reverse+0x126>
jmp    128b <reverse+0x12b>
mov    -0xbc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xbc(%rbp)
jmp    11a4 <reverse+0x44>
cmpl   $0x0,-0xb8(%rbp)
jle    12e5 <reverse+0x185>
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xb8(%rbp),%edx
call   1030 <strncpy@plt>
lea    -0x60(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <strcpy@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rdi,%r13
mov    %rsp,%rdi
xor    %ebp,%ebp
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
js     1245 <reverse+0xe5>
mov    %eax,%ebx
add    $0x1,%rbx
lea    0x50(%rsp),%r14
mov    %rsp,%r15
lea    0xe56(%rip),%r12
jmp    11c6 <reverse+0x66>
nopl   0x0(%rax)
movsbl %al,%edi
call   1060 <isalnum@plt>
test   %rax,%rax
je     120b <reverse+0xab>
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
jle    1215 <reverse+0xb5>
movzbl -0x1(%r13,%rbx,1),%eax
cmp    $0x20,%al
jne    11b0 <reverse+0x50>
test   %ebp,%ebp
jle    11b0 <reverse+0x50>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
lea    (%rbx,%r13,1),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
xor    %ebp,%ebp
jmp    11c0 <reverse+0x60>
cmpb   $0x27,-0x1(%r13,%rbx,1)
je     11bd <reverse+0x5d>
jmp    11c0 <reverse+0x60>
test   %ebp,%ebp
jle    1245 <reverse+0xe5>
lea    0x50(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x50,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
mov    %rsp,%rsi
mov    %r13,%rdi
call   1040 <strcpy@plt>
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca [80 x i8]
%4 = alloca [80 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 80)
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
store i32 0, i32* %6
%12 = load i32, i32* %5
store i32 %12, i32* %7
br label %13
13: ; preds = %64, %1
%14 = load i32, i32* %7
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %67
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 32
br i1 %23, label %24, label %43
24: ; preds = %16
%25 = load i32, i32* %6
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %24
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%29 = call i32 @memset(i8* %28, i32 0, i32 80)
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%31 = load i8*, i8** %2
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i32, i32* %6
%37 = call i32 @strncpy(i8* %30, i8* %35, i32 %36)
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
br label %63
43: ; preds = %24, %16
%44 = load i8*, i8** %2
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = call i64 @isalnum(i8 signext %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %59, label %51
51: ; preds = %43
%52 = load i8*, i8** %2
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 39
br i1 %58, label %59, label %62
59: ; preds = %51, %43
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %62
62: ; preds = %59, %51
br label %63
63: ; preds = %62, %27
br label %64
64: ; preds = %63
%65 = load i32, i32* %7
%66 = add nsw i32 %65, -1
store i32 %66, i32* %7
br label %13
67: ; preds = %13
%68 = load i32, i32* %6
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %67
%71 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%72 = call i32 @memset(i8* %71, i32 0, i32 80)
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%74 = load i8*, i8** %2
%75 = load i32, i32* %6
%76 = call i32 @strncpy(i8* %73, i8* %74, i32 %75)
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%79 = call i32 @strcat(i8* %77, i8* %78)
br label %80
80: ; preds = %70, %67
%81 = load i8*, i8** %2
%82 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%83 = call i32 @strcpy(i8* %81, i8* %82)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @reverse(i8* %0) {
%2 = alloca [80 x i8]
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %4, i32 0, i32 80)
%7 = call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %43
9: ; preds = %1
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %33
%12 = phi i64 [ %10, %9 ], [ %35, %33 ]
%13 = phi i32 [ 0, %9 ], [ %34, %33 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %12
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 32
%17 = icmp sgt i32 %13, 0
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = call i32 @memset(i8* %5, i32 0, i32 80)
%21 = getelementptr inbounds i8, i8* %14, i64 1
%22 = call i32 @strncpy(i8* %5, i8* %21, i32 %13)
%23 = call i32 @strcat(i8* %4, i8* %5)
%24 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %33
25: ; preds = %11
%26 = call i64 @isalnum(i8 signext %15)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8, i8* %14
%30 = icmp eq i8 %29, 39
br i1 %30, label %31, label %33
31: ; preds = %28, %25
%32 = add nsw i32 %13, 1
br label %33
33: ; preds = %19, %31, %28
%34 = phi i32 [ 0, %19 ], [ %32, %31 ], [ %13, %28 ]
%35 = add nsw i64 %12, -1
%36 = icmp sgt i64 %12, 0
br i1 %36, label %11, label %37
37: ; preds = %33
%38 = icmp sgt i32 %34, 0
br i1 %38, label %39, label %43
39: ; preds = %37
%40 = call i32 @memset(i8* %5, i32 0, i32 80)
%41 = call i32 @strncpy(i8* %5, i8* %0, i32 %34)
%42 = call i32 @strcat(i8* %4, i8* %5)
br label %43
43: ; preds = %1, %39, %37
%44 = call i32 @strcpy(i8* %0, i8* %4)
ret void
}