#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*/ printf(char *, ...);
int strlen(char *);
int /*<<< orphan*/ swap(char *, char *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("Error! To run this program correctly, type:\n");
    printf("./strinvert string\n");
    printf("Aborting...\n");
    return -1;
  }
  printf("Non-inverted (input) string:\t %s\n", argv[1]);
  int len = strlen(argv[1]);
  int maxindex, index;
  if (len == 1) {
    printf("Inverted (output) string:\t %s\n", argv[1]);
    return 0;
  }
  if (len % 2 == 0)
    maxindex = (len / 2);
  else
    maxindex = ((len - 1) / 2);
  for (index = 0; index < maxindex; index++)
    swap(&argv[1][index], &argv[1][len - 1 - index]);
  printf("Inverted (output) string:\t %s\n", argv[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1186 <main+0x56>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <main+0x148>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11d8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1278 <main+0x148>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ff <main+0xcf>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    1210 <main+0xe0>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    125b <main+0x12b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
sub    -0x1c(%rbp),%eax
cltq
add    %rax,%rsi
call   1050 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1217 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    117e <main+0x3e>
mov    %rsi,%r14
mov    0x8(%rsi),%rsi
lea    0xea6(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%r14),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jne    11a9 <main+0x69>
mov    0x8(%r14),%rsi
lea    0xea6(%rip),%rdi
jmp    11ec <main+0xac>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    11f3 <main+0xb3>
mov    %eax,%ebx
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jl     11df <main+0x9f>
mov    %ebx,%r15d
shr    %r15d
add    $0xffffffff,%ebx
xor    %ebp,%ebp
xchg   %ax,%ax
mov    0x8(%r14),%rsi
lea    (%rsi,%rbp,1),%rdi
movslq %ebx,%rbx
add    %rbx,%rsi
call   1060 <swap@plt>
add    $0x1,%rbp
add    $0xffffffff,%ebx
cmp    %rbp,%r15
jne    11c0 <main+0x80>
mov    0x8(%r14),%rsi
lea    0xe38(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"Error! To run this program correctly, type:\0A\00"
@.str.1 = [20 x i8] c"./strinvert string\0A\00"
@.str.2 = [13 x i8] c"Aborting...\0A\00"
@.str.3 = [34 x i8] c"Non-inverted (input) string:\09 %s\0A\00"
@.str.4 = [31 x i8] c"Inverted (output) string:\09 %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %72
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %31
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %29)
store i32 0, i32* %3
br label %72
31: ; preds = %15
%32 = load i32, i32* %6
%33 = srem i32 %32, 2
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* %6
%37 = sdiv i32 %36, 2
store i32 %37, i32* %7
br label %42
38: ; preds = %31
%39 = load i32, i32* %6
%40 = sub nsw i32 %39, 1
%41 = sdiv i32 %40, 2
store i32 %41, i32* %7
br label %42
42: ; preds = %38, %35
store i32 0, i32* %8
br label %43
43: ; preds = %64, %42
%44 = load i32, i32* %8
%45 = load i32, i32* %7
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %67
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = load i32, i32* %8
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 1
%59 = load i32, i32* %8
%60 = sub nsw i32 %58, %59
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %56, i64 %61
%63 = call i32 @swap(i8* %53, i8* %62)
br label %64
64: ; preds = %47
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %43
67: ; preds = %43
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 1
%70 = load i8*, i8** %69
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %67, %26, %11
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str.3 = [34 x i8] c"Non-inverted (input) string:\09 %s\0A\00"
@.str.4 = [31 x i8] c"Inverted (output) string:\09 %s\0A\00"
@str = [44 x i8] c"Error! To run this program correctly, type:\00"
@str.5 = [19 x i8] c"./strinvert string\00"
@str.6 = [12 x i8] c"Aborting...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0))
br label %39
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %9
%13 = tail call i32 @strlen(i8* %12)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i8*, i8** %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %16)
br label %39
18: ; preds = %8
%19 = and i32 %13, -2
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %36
21: ; preds = %18
%22 = lshr i32 %13, 1
%23 = zext i32 %22 to i64
br label %24
24: ; preds = %21, %24
%25 = phi i64 [ 0, %21 ], [ %34, %24 ]
%26 = load i8*, i8** %9
%27 = getelementptr inbounds i8, i8* %26, i64 %25
%28 = trunc i64 %25 to i32
%29 = xor i32 %28, -1
%30 = add i32 %13, %29
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %26, i64 %31
%33 = tail call i32 @swap(i8* %27, i8* %32)
%34 = add nuw nsw i64 %25, 1
%35 = icmp eq i64 %34, %23
br i1 %35, label %36, label %24
36: ; preds = %24, %18
%37 = load i8*, i8** %9
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %15, %36, %4
%40 = phi i32 [ -1, %4 ], [ 0, %36 ], [ 0, %15 ]
ret i32 %40
}