#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 atoi(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int twistANumber(int num) {
  int i = num, counter = 0;
  while (i != 0) {
    i /= 10;
    ++counter;
  }
  char buffer[counter + 1];
  sprintf(buffer, "%d", num);
  for (i = 0; buffer[i] != '\0'; ++i) {
    if (buffer[i] == '3')
      buffer[i] = '7';
    else if (buffer[i] == '7')
      buffer[i] = '3';
  }
  return atoi(buffer);
}


x86 assembly (clang, -O0):
<twistANumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115e <twistANumber+0x3e>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <twistANumber+0x18>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edx
lea    0xe6f(%rip),%rsi
call   1040 <sprintf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1211 <twistANumber+0xf1>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x33,%eax
jne    11d8 <twistANumber+0xb8>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x37,(%rax,%rcx,1)
jmp    11fe <twistANumber+0xde>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x37,%eax
jne    11f9 <twistANumber+0xd9>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x33,(%rax,%rcx,1)
jmp    11fe <twistANumber+0xde>
jmp    1203 <twistANumber+0xe3>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119d <twistANumber+0x7d>
mov    -0x28(%rbp),%rdi
call   1030 <atoi@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<twistANumber>:
mov    %edi,%edx
test   %edi,%edi
je     1156 <twistANumber+0x36>
mov    $0x1,%eax
mov    %edx,%ecx
nopl   (%rax)
movslq %ecx,%rsi
imul   $0x66666667,%rsi,%rcx
mov    %rcx,%rdi
shr    $0x3f,%rdi
sar    $0x22,%rcx
add    %edi,%ecx
add    $0x1,%eax
add    $0x9,%esi
cmp    $0x12,%esi
ja     1130 <twistANumber+0x10>
mov    %eax,%eax
jmp    115b <twistANumber+0x3b>
mov    $0x1,%eax
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe87(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
jmp    1198 <twistANumber+0x78>
cs nopw 0x0(%rax,%rax,1)
mov    $0x33,%cl
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x33,%cl
je     11b0 <twistANumber+0x90>
cmp    $0x37,%cl
je     1190 <twistANumber+0x70>
test   %cl,%cl
jne    1194 <twistANumber+0x74>
jmp    11b4 <twistANumber+0x94>
nopl   0x0(%rax,%rax,1)
mov    $0x37,%cl
jmp    1192 <twistANumber+0x72>
mov    %rbx,%rdi
call   1030 <atoi@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @twistANumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 %0, i32* %2
%7 = load i32, i32* %2
store i32 %7, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %11, %1
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 10
store i32 %13, i32* %3
%14 = load i32, i32* %4
%15 = add nsw i32 %14, 1
store i32 %15, i32* %4
br label %8
16: ; preds = %8
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %5
%21 = alloca i8, i64 %19
store i64 %19, i64* %6
%22 = load i32, i32* %2
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 0, i32* %3
br label %24
24: ; preds = %55, %16
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %21, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %58
31: ; preds = %24
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %21, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 51
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %21, i64 %40
store i8 55, i8* %41
br label %54
42: ; preds = %31
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %21, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 55
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i32, i32* %3
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %21, i64 %51
store i8 51, i8* %52
br label %53
53: ; preds = %49, %42
br label %54
54: ; preds = %53, %38
br label %55
55: ; preds = %54
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %24
58: ; preds = %24
%59 = call i32 @atoi(i8* %21)
%60 = load i8*, i8** %5
ret i32 %59
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @twistANumber(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %12, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ %0, %1 ]
%5 = phi i32 [ %7, %3 ], [ 1, %1 ]
%6 = sdiv i32 %4, 10
%7 = add i32 %5, 1
%8 = add i32 %4, 9
%9 = icmp ult i32 %8, 19
br i1 %9, label %10, label %3
10: ; preds = %3
%11 = zext i32 %7 to i64
br label %12
12: ; preds = %10, %1
%13 = phi i64 [ 1, %1 ], [ %11, %10 ]
%14 = alloca i8, i64 %13
%15 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %23, %12
%17 = phi i64 [ %24, %23 ], [ 0, %12 ]
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
switch i8 %19, label %23 [
i8 0, label %25
i8 51, label %21
i8 55, label %20
]
20: ; preds = %16
br label %21
21: ; preds = %16, %20
%22 = phi i8 [ 51, %20 ], [ 55, %16 ]
store i8 %22, i8* %18
br label %23
23: ; preds = %21, %16
%24 = add nuw i64 %17, 1
br label %16
25: ; preds = %16
%26 = call i32 @atoi(i8* %14)
ret i32 %26
}