#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *ssid_rework(const char *before) {
  unsigned int i;
  char *ch1;
  int flag_hex = 0;
  static char after[32 * 4 + 1];
  memset(after, 0, 32 * 4 + 1);
  if (before == 0)
    return after;
  for (i = 0; i < strlen(before); i++) {
    if (before[i] < 32 || before[i] > 127) {
      flag_hex = 1;
      break;
    }
  }
  ch1 = &after[0];
  if (flag_hex) {
    i = 0;
    for (;;) {
      if (before[i] == 0)
        break;
      sprintf(ch1, "%02x", (unsigned char)before[i]);
      ch1 += 2;
      i++;
    }
  } else {
    after[0] = '"';
    strcpy(after + 1, before);
    after[strlen(before) + 1] = '"';
  }
  return after;
}


x86 assembly (clang, -O0):
<ssid_rework>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0x2ef6(%rip),%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1181 <ssid_rework+0x41>
lea    0x2ed8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1296 <ssid_rework+0x156>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jae    11eb <ssid_rework+0xab>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11cc <ssid_rework+0x8c>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jle    11d8 <ssid_rework+0x98>
movl   $0x1,-0x24(%rbp)
jmp    11eb <ssid_rework+0xab>
jmp    11dd <ssid_rework+0x9d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1188 <ssid_rework+0x48>
lea    0x2e5e(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     125a <ssid_rework+0x11a>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1220 <ssid_rework+0xe0>
jmp    1255 <ssid_rework+0x115>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
lea    0xdce(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1207 <ssid_rework+0xc7>
jmp    128b <ssid_rework+0x14b>
movb   $0x22,0x2def(%rip)
mov    -0x10(%rbp),%rsi
lea    0x2de5(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2dc9(%rip),%rax
movb   $0x22,(%rax,%rcx,1)
lea    0x2dbe(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssid_rework>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0x2eff(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x81,%edx
call   1050 <memset@plt>
test   %r14,%r14
je     1200 <ssid_rework+0xc0>
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     119a <ssid_rework+0x5a>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cmpb   $0x1f,(%r14,%rbp,1)
jle    11c8 <ssid_rework+0x88>
add    $0x1,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     1180 <ssid_rework+0x40>
movb   $0x22,0x2eaf(%rip)
lea    0x2ea8(%rip),%rbx
lea    0x2ea2(%rip),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x22,0x1(%rax,%rbx,1)
jmp    1200 <ssid_rework+0xc0>
mov    (%r14),%al
test   %al,%al
je     1200 <ssid_rework+0xc0>
mov    $0x1,%ebp
lea    0xe25(%rip),%r15
nopl   0x0(%rax,%rax,1)
movzbl %al,%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <sprintf@plt>
add    $0x2,%rbx
mov    %ebp,%eax
movzbl (%r14,%rax,1),%eax
add    $0x1,%ebp
test   %al,%al
jne    11e0 <ssid_rework+0xa0>
lea    0x2e49(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@ssid_rework.after = internal global [129 x i8] zeroinitializer
@.str = [5 x i8] c"%02x\00"
define i8* @ssid_rework(i8* %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 0), i32 0, i32 129)
%3 = icmp eq i8* %0, null
br i1 %3, label %37, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %31, label %11
7: ; preds = %11
%8 = tail call i32 @strlen(i8* %0)
%9 = zext i32 %8 to i64
%10 = icmp ult i64 %16, %9
br i1 %10, label %11, label %31
11: ; preds = %4, %7
%12 = phi i64 [ %16, %7 ], [ 0, %4 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp slt i8 %14, 32
%16 = add nuw nsw i64 %12, 1
br i1 %15, label %17, label %7
17: ; preds = %11
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %37, label %20
20: ; preds = %17, %20
%21 = phi i8 [ %29, %20 ], [ %18, %17 ]
%22 = phi i8* [ %25, %20 ], [ getelementptr inbounds ([129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 0), %17 ]
%23 = phi i32 [ %26, %20 ], [ 0, %17 ]
%24 = tail call i32 @sprintf(i8* dereferenceable(1) %22, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %21)
%25 = getelementptr inbounds i8, i8* %22, i64 2
%26 = add i32 %23, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %37, label %20
31: ; preds = %7, %4
store i8 34, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 0)
%32 = tail call i32 @strcpy(i8* getelementptr inbounds ([129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 1), i8* %0)
%33 = tail call i32 @strlen(i8* %0)
%34 = add nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 %35
store i8 34, i8* %36
br label %37
37: ; preds = %20, %17, %31, %1
ret i8* getelementptr inbounds ([129 x i8], [129 x i8]* @ssid_rework.after, i64 0, i64 0)
}