#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*/ strcpy(char *, char *);
void complement(unsigned char *buffer) {
  register unsigned char *ptr;
  register short i, index;
  static unsigned char conv[0377 + 2];
  index = 0;
  for (i = 1; i <= 0377; i++) {
    for (ptr = buffer; *ptr; ptr++)
      if (*ptr == i)
        break;
    if (*ptr == '\0')
      conv[index++] = i & 0377;
  }
  conv[index] = '\0';
  strcpy((char *)buffer, (char *)conv);
}


x86 assembly (clang, -O0):
<complement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movw   $0x0,-0x14(%rbp)
movw   $0x1,-0x12(%rbp)
movswl -0x12(%rbp),%eax
cmp    $0xff,%eax
jg     11c8 <complement+0xb8>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     117a <complement+0x6a>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
movswl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jne    1164 <complement+0x54>
jmp    117a <complement+0x6a>
jmp    1169 <complement+0x59>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113f <complement+0x2f>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
jne    11b2 <complement+0xa2>
movswl -0x12(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x14(%rbp),%ax
mov    %ax,%cx
add    $0x1,%cx
mov    %cx,-0x14(%rbp)
movswq %ax,%rcx
lea    0x2e91(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    11b7 <complement+0xa7>
mov    -0x12(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x12(%rbp)
jmp    1128 <complement+0x18>
movswq -0x14(%rbp),%rcx
lea    0x2e6c(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0x2e5d(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complement>:
mov    $0x1,%r9d
xor    %r8d,%r8d
lea    0x2f20(%rip),%rsi
jmp    1134 <complement+0x24>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%r9d
mov    %rdi,%rdx
nopw   0x0(%rax,%rax,1)
movzbl (%rdx),%ecx
test   %ecx,%ecx
je     1150 <complement+0x40>
add    $0x1,%rdx
cmp    %ecx,%r9d
jne    1140 <complement+0x30>
test   %cl,%cl
jne    1163 <complement+0x53>
movswq %r8w,%rax
lea    0x1(%r8),%ecx
mov    %r9b,(%rax,%rsi,1)
mov    %ecx,%r8d
lea    0x1(%r9),%edx
cmp    $0x100,%edx
je     11a3 <complement+0x93>
mov    %rdi,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rcx),%eax
test   %eax,%eax
je     118f <complement+0x7f>
add    $0x1,%rcx
cmp    %eax,%edx
jne    1180 <complement+0x70>
test   %al,%al
jne    1130 <complement+0x20>
movswq %r8w,%rax
lea    0x1(%r8),%ecx
mov    %dl,(%rax,%rsi,1)
mov    %ecx,%r8d
jmp    1130 <complement+0x20>
movswq %r8w,%rax
movb   $0x0,(%rax,%rsi,1)
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@complement.conv = internal global [257 x i8] zeroinitializer
define void @complement(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i16
%5 = alloca i16
store i8* %0, i8** %2
store i16 0, i16* %5
store i16 1, i16* %4
br label %6
6: ; preds = %43, %1
%7 = load i16, i16* %4
%8 = sext i16 %7 to i32
%9 = icmp sle i32 %8, 255
br i1 %9, label %10, label %46
10: ; preds = %6
%11 = load i8*, i8** %2
store i8* %11, i8** %3
br label %12
12: ; preds = %25, %10
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = load i16, i16* %4
%21 = sext i16 %20 to i32
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %16
br label %28
24: ; preds = %16
br label %25
25: ; preds = %24
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
br label %12
28: ; preds = %23, %12
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %28
%34 = load i16, i16* %4
%35 = sext i16 %34 to i32
%36 = and i32 %35, 255
%37 = trunc i32 %36 to i8
%38 = load i16, i16* %5
%39 = add i16 %38, 1
store i16 %39, i16* %5
%40 = sext i16 %38 to i64
%41 = getelementptr inbounds [257 x i8], [257 x i8]* @complement.conv, i64 0, i64 %40
store i8 %37, i8* %41
br label %42
42: ; preds = %33, %28
br label %43
43: ; preds = %42
%44 = load i16, i16* %4
%45 = add i16 %44, 1
store i16 %45, i16* %4
br label %6
46: ; preds = %6
%47 = load i16, i16* %5
%48 = sext i16 %47 to i64
%49 = getelementptr inbounds [257 x i8], [257 x i8]* @complement.conv, i64 0, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %2
%51 = call i32 @strcpy(i8* %50, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @complement.conv, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@complement.conv = internal global [257 x i8] zeroinitializer
define void @complement(i8* %0) {
br label %2
2: ; preds = %37, %1
%3 = phi i32 [ 1, %1 ], [ %39, %37 ]
%4 = phi i16 [ 0, %1 ], [ %38, %37 ]
br label %5
5: ; preds = %5, %2
%6 = phi i8* [ %12, %5 ], [ %0, %2 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = zext i8 %7 to i32
%10 = icmp eq i32 %3, %9
%11 = select i1 %8, i1 true, i1 %10
%12 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %11, label %13, label %5
13: ; preds = %5
br i1 %8, label %14, label %19
14: ; preds = %13
%15 = trunc i32 %3 to i8
%16 = add i16 %4, 1
%17 = sext i16 %4 to i64
%18 = getelementptr inbounds [257 x i8], [257 x i8]* @complement.conv, i64 0, i64 %17
store i8 %15, i8* %18
br label %19
19: ; preds = %13, %14
%20 = phi i16 [ %16, %14 ], [ %4, %13 ]
%21 = add nuw nsw i32 %3, 1
%22 = icmp eq i32 %21, 256
br i1 %22, label %40, label %23
23: ; preds = %19, %23
%24 = phi i8* [ %30, %23 ], [ %0, %19 ]
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
%27 = zext i8 %25 to i32
%28 = icmp eq i32 %21, %27
%29 = select i1 %26, i1 true, i1 %28
%30 = getelementptr inbounds i8, i8* %24, i64 1
br i1 %29, label %31, label %23
31: ; preds = %23
br i1 %26, label %32, label %37
32: ; preds = %31
%33 = trunc i32 %21 to i8
%34 = add i16 %20, 1
%35 = sext i16 %20 to i64
%36 = getelementptr inbounds [257 x i8], [257 x i8]* @complement.conv, i64 0, i64 %35
store i8 %33, i8* %36
br label %37
37: ; preds = %32, %31
%38 = phi i16 [ %34, %32 ], [ %20, %31 ]
%39 = add nuw nsw i32 %3, 2
br label %2
40: ; preds = %19
%41 = sext i16 %20 to i64
%42 = getelementptr inbounds [257 x i8], [257 x i8]* @complement.conv, i64 0, i64 %41
store i8 0, i8* %42
%43 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @complement.conv, i64 0, i64 0))
ret void
}