void main() {
  char *tmp;
  char *b = "1101";
  printf("%d\n", strtol(b, &tmp, 2));
  printf("%x\n", strtol(b, &tmp, 2));
  printf("%s\n", byte_to_binary(4));
  printf("%s\n", byte_to_binary(16));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1050 <strtol@plt>
mov    %rax,%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x2,%edx
call   1050 <strtol@plt>
mov    %rax,%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4,%edi
mov    $0x0,%al
call   1030 <byte_to_binary@plt>
mov    %eax,%esi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x10,%edi
mov    $0x0,%al
call   1030 <byte_to_binary@plt>
mov    %eax,%esi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rbx
mov    %rsp,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <strtol@plt>
lea    0xeb0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <strtol@plt>
lea    0xe93(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x4,%edi
xor    %eax,%eax
call   1030 <byte_to_binary@plt>
lea    0xe7a(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x10,%edi
xor    %eax,%eax
call   1030 <byte_to_binary@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"1101\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%x\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @main() {
%1 = alloca i8*
%2 = alloca i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
%3 = load i8*, i8** %2
%4 = call i64 @strtol(i8* %3, i8** %1, i32 2)
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %4)
%6 = load i8*, i8** %2
%7 = call i64 @strtol(i8* %6, i8** %1, i32 2)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %7)
%9 = call i32 (i32, ...) bitcast (i32 (...)* @byte_to_binary to i32 (i32, ...)*)(i32 4)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = call i32 (i32, ...) bitcast (i32 (...)* @byte_to_binary to i32 (i32, ...)*)(i32 16)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"1101\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [4 x i8] c"%x\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @main() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call i64 @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %1, i32 2)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%5 = call i64 @strtol(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %1, i32 2)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @byte_to_binary to i32 (i32, ...)*)(i32 4)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @byte_to_binary to i32 (i32, ...)*)(i32 16)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %9)
ret void
}