#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 */
scalar_t__ poww(int);
int /*<<< orphan*/ printf(char *, int);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i;
  int bits[64] = {0};
  int j;
  if (argc != 2)
    return -1;
  i = strtol(argv[1], NULL, 0);
  printf("before 0x%x\n", i);
  for (j = 0; j < 64; j++)
    if (i & (1 << j))
      bits[j] = 1;
  i = 0;
  for (j = 0; j < 64; j++)
    if (bits[j] == 1)
      i += poww(63 - j);
  printf("after 0x%x\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     1182 <main+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    1285 <main+0x145>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x124(%rbp)
cmpl   $0x40,-0x124(%rbp)
jge    1206 <main+0xc6>
mov    -0x14(%rbp),%eax
mov    -0x124(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11ed <main+0xad>
movslq -0x124(%rbp),%rax
movl   $0x1,-0x120(%rbp,%rax,4)
jmp    11f2 <main+0xb2>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    11b1 <main+0x71>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x124(%rbp)
cmpl   $0x40,-0x124(%rbp)
jge    126f <main+0x12f>
movslq -0x124(%rbp),%rax
cmpl   $0x1,-0x120(%rbp,%rax,4)
01
jne    1256 <main+0x116>
mov    $0x3f,%edi
sub    -0x124(%rbp),%edi
call   1060 <poww@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    125b <main+0x11b>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1217 <main+0xd7>
mov    -0x14(%rbp),%esi
lea    0xd94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jne    1250 <main+0x120>
mov    0x8(%rsi),%rdi
xor    %ebp,%ebp
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,%ebx
lea    0xe35(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    11ed <main+0xbd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rax
mov    %rax,%rbp
cmp    $0x40,%rax
je     120c <main+0xdc>
bt     %ebp,%ebx
jae    11f9 <main+0xc9>
movl   $0x1,(%rsp,%rbp,4)
lea    0x1(%rbp),%rax
bt     %eax,%ebx
jae    11e0 <main+0xb0>
movl   $0x1,0x4(%rsp,%rbp,4)
jmp    11e0 <main+0xb0>
xor    %ebx,%ebx
mov    $0x3f,%ebp
xor    %r14d,%r14d
jmp    122d <main+0xfd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x40,%rbx
je     123f <main+0x10f>
cmpl   $0x1,(%rsp,%rbx,4)
jne    1220 <main+0xf0>
mov    %ebp,%edi
call   1050 <poww@plt>
add    %eax,%r14d
jmp    1220 <main+0xf0>
lea    0xdc7(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"before 0x%x\0A\00"
@.str.1 = [12 x i8] c"after 0x%x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [64 x i32]
%4 = bitcast [64 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %48
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %27, %6
%12 = phi i64 [ 0, %6 ], [ %28, %27 ]
%13 = trunc i64 %12 to i32
%14 = shl nuw i32 1, %13
%15 = and i32 %14, %9
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %12
store i32 1, i32* %18
br label %19
19: ; preds = %11, %17
%20 = or i64 %12, 1
%21 = trunc i64 %20 to i32
%22 = shl nuw i32 1, %21
%23 = and i32 %22, %9
%24 = icmp eq i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %20
store i32 1, i32* %26
br label %27
27: ; preds = %25, %19
%28 = add nuw nsw i64 %12, 2
%29 = icmp eq i64 %28, 64
br i1 %29, label %30, label %11
30: ; preds = %27, %42
%31 = phi i64 [ %44, %42 ], [ 0, %27 ]
%32 = phi i32 [ %43, %42 ], [ 0, %27 ]
%33 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %31
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 1
br i1 %35, label %36, label %42
36: ; preds = %30
%37 = trunc i64 %31 to i32
%38 = sub i32 63, %37
%39 = tail call i64 @poww(i32 %38)
%40 = trunc i64 %39 to i32
%41 = add i32 %32, %40
br label %42
42: ; preds = %30, %36
%43 = phi i32 [ %41, %36 ], [ %32, %30 ]
%44 = add nuw nsw i64 %31, 1
%45 = icmp eq i64 %44, 64
br i1 %45, label %46, label %30
46: ; preds = %42
%47 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %43)
br label %48
48: ; preds = %2, %46
%49 = phi i32 [ 0, %46 ], [ -1, %2 ]
ret i32 %49
}