#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__ malloc(scalar_t__);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void disp(char *s) {
  int i, val = 0;
  char *t;
  t = (char *)malloc(strlen(s) + 1);
  strcpy(t, s);
  for (i = 0; t[i] != '\0'; i++)
    val = val * 2 + 1 + t[i] - '0';
  printf(" %d %s\n", val, t);
}


x86 assembly (clang, -O0):
<disp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c0 <disp+0x80>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    -0x18(%rbp),%rcx
movslq -0xc(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1180 <disp+0x40>
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disp>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    (%r14),%cl
test   %cl,%cl
je     1196 <disp+0x56>
mov    %r14,%rax
add    $0x1,%rax
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %cl,%ecx
lea    (%rcx,%rsi,2),%esi
add    $0xffffffd1,%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1180 <disp+0x40>
jmp    1198 <disp+0x58>
xor    %esi,%esi
lea    0xe61(%rip),%rdi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c" %d %s\0A\00"
define void @disp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 %7, 1
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %11, i8* %12)
store i32 0, i32* %3
br label %14
14: ; preds = %34, %1
%15 = load i8*, i8** %5
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %14
%23 = load i32, i32* %4
%24 = mul nsw i32 %23, 2
%25 = add nsw i32 %24, 1
%26 = load i8*, i8** %5
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = add nsw i32 %25, %31
%33 = sub nsw i32 %32, 48
store i32 %33, i32* %4
br label %34
34: ; preds = %22
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %14
37: ; preds = %14
%38 = load i32, i32* %4
%39 = load i8*, i8** %5
%40 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %38, i8* %39)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c" %d %s\0A\00"
define void @disp(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = load i8, i8* %5
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %17, %9 ], [ 0, %1 ]
%11 = phi i8 [ %19, %9 ], [ %7, %1 ]
%12 = phi i32 [ %16, %9 ], [ 0, %1 ]
%13 = sext i8 %11 to i32
%14 = shl nsw i32 %12, 1
%15 = add i32 %14, -47
%16 = add i32 %15, %13
%17 = add nuw nsw i64 %10, 1
%18 = getelementptr inbounds i8, i8* %5, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %9, %1
%22 = phi i32 [ 0, %1 ], [ %16, %9 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %22, i8* %5)
ret void
}