#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void reverse_buffer(char *buffer, int num_nodes) {
  int i;
  char temp[50];
  char *ptr;
  for (i = 0; i < num_nodes / 2; ++i) {
    strncpy(temp, &buffer[i * 50], 50);
    if (strlen(&buffer[i * 50]) > 50) {
      temp[50 - 1] = '\0';
    }
    strncpy(&buffer[i * 50], &buffer[(num_nodes - i - 1) * 50], 50);
    if (strlen(&buffer[(num_nodes - i - 1) * 50]) > 50) {
      ptr = &buffer[i * 50];
      ptr[50 - 1] = '\0';
    }
    strncpy(&buffer[(num_nodes - i - 1) * 50], temp, 50);
    if (strlen(temp) > 50) {
      ptr = &buffer[(num_nodes - i - 1) * 50];
      ptr[50 - 1] = '\0';
    }
  }
}


x86 assembly (clang, -O0):
<reverse_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
cmp    %ecx,%eax
jge    1261 <reverse_buffer+0x141>
lea    -0x50(%rbp),%rdi
mov    -0x8(%rbp),%rsi
imul   $0x32,-0x10(%rbp),%eax
cltq
add    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
imul   $0x32,-0x10(%rbp),%eax
cltq
add    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x32,%eax
jle    118e <reverse_buffer+0x6e>
movb   $0x0,-0x1f(%rbp)
mov    -0x8(%rbp),%rdi
imul   $0x32,-0x10(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
imul   $0x32,%eax,%eax
cltq
add    %rax,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
imul   $0x32,%eax,%eax
cltq
add    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x32,%eax
jle    11f7 <reverse_buffer+0xd7>
mov    -0x8(%rbp),%rax
imul   $0x32,-0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movb   $0x0,0x31(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
imul   $0x32,%eax,%eax
cltq
add    %rax,%rdi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x32,%eax
jle    124e <reverse_buffer+0x12e>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
imul   $0x32,%ecx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movb   $0x0,0x31(%rax)
jmp    1253 <reverse_buffer+0x133>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <reverse_buffer+0x16>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
cmp    $0x2,%esi
jl     11ca <reverse_buffer+0xaa>
mov    %esi,%r12d
mov    %rdi,%r14
imul   $0x32,%esi,%ebp
shr    %r12d
add    $0xffffffce,%ebp
mov    %rsp,%r15
mov    %rdi,%r13
jmp    115d <reverse_buffer+0x3d>
xchg   %ax,%ax
add    $0xffffffce,%ebp
add    $0x32,%r13
add    $0xffffffffffffffff,%r12
je     11ca <reverse_buffer+0xaa>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    $0x33,%eax
jl     117f <reverse_buffer+0x5f>
movb   $0x0,0x31(%rsp)
movslq %ebp,%rbx
add    %r14,%rbx
mov    %r13,%rdi
mov    %rbx,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x33,%eax
jl     11a7 <reverse_buffer+0x87>
movb   $0x0,0x31(%r13)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x32,%edx
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cmp    $0x33,%eax
jl     1150 <reverse_buffer+0x30>
movb   $0x0,0x31(%rbx)
jmp    1150 <reverse_buffer+0x30>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @reverse_buffer(i8* %0, i32 %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %39
6: ; preds = %2
%7 = lshr i32 %1, 1
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 49
%9 = zext i32 %7 to i64
br label %10
10: ; preds = %6, %36
%11 = phi i64 [ 0, %6 ], [ %37, %36 ]
%12 = mul nuw nsw i64 %11, 50
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i32 @strncpy(i8* %4, i8* %13, i32 50)
%15 = call i32 @strlen(i8* %13)
%16 = icmp sgt i32 %15, 50
br i1 %16, label %17, label %18
17: ; preds = %10
store i8 0, i8* %8
br label %18
18: ; preds = %17, %10
%19 = trunc i64 %11 to i32
%20 = xor i32 %19, -1
%21 = add i32 %20, %1
%22 = mul nsw i32 %21, 50
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = call i32 @strncpy(i8* %13, i8* %24, i32 50)
%26 = call i32 @strlen(i8* %24)
%27 = icmp sgt i32 %26, 50
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = getelementptr inbounds i8, i8* %13, i64 49
store i8 0, i8* %29
br label %30
30: ; preds = %28, %18
%31 = call i32 @strncpy(i8* %24, i8* %4, i32 50)
%32 = call i32 @strlen(i8* %4)
%33 = icmp sgt i32 %32, 50
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %24, i64 49
store i8 0, i8* %35
br label %36
36: ; preds = %30, %34
%37 = add nuw nsw i64 %11, 1
%38 = icmp eq i64 %37, %9
br i1 %38, label %39, label %10
39: ; preds = %36, %2
ret void
}