#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(int);
char *power_of_two_binary(unsigned int power) {
  char *a;
  a = (char *)malloc(sizeof(char) * power + 1 + 1);
  a[0] = '1';
  int i;
  for (i = 1; i <= power; i++) {
    a[i] = '0';
  }
  a[i] = '\0';
  return a;
}


x86 assembly (clang, -O0):
<power_of_two_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x0,%rax
add    $0x1,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x31,(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
ja     1169 <power_of_two_binary+0x59>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <power_of_two_binary+0x33>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_of_two_binary>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x2(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movb   $0x31,(%rax)
test   %ebx,%ebx
je     1150 <power_of_two_binary+0x30>
mov    %r14,%rdi
add    $0x1,%rdi
mov    %ebx,%edx
mov    $0x30,%esi
call   1030 <memset@plt>
add    $0x1,%ebx
jmp    1155 <power_of_two_binary+0x35>
mov    $0x1,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @power_of_two_binary(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = zext i32 %5 to i64
%7 = mul i64 1, %6
%8 = add i64 %7, 1
%9 = add i64 %8, 1
%10 = trunc i64 %9 to i32
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 0
store i8 49, i8* %14
store i32 1, i32* %4
br label %15
15: ; preds = %24, %1
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp ule i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 48, i8* %23
br label %24
24: ; preds = %19
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %15
27: ; preds = %15
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
define i8* @power_of_two_binary(i32 %0) {
%2 = add i32 %0, 2
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
store i8 49, i8* %4
%5 = icmp eq i32 %0, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = getelementptr i8, i8* %4, i64 1
%8 = zext i32 %0 to i64
%9 = add i32 %0, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %6, %1
%12 = phi i64 [ 1, %1 ], [ %10, %6 ]
%13 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 0, i8* %13
ret i8* %4
}