#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 /*<<< orphan*/ putchar(char);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int nbits = strtol(argv[1], NULL, 10);
  for (unsigned long i = 0; i < (1UL << nbits); i++) {
    unsigned long g = i ^ (i >> 1);
    for (int b = nbits - 1; b >= 0; b--)
      putchar('0' + ((g >> b) & 1));
    putchar('\n');
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
cmp    %rcx,%rax
jae    11db <main+0xbb>
mov    -0x20(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x1,%rcx
xor    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     11c0 <main+0xa0>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
shr    %cl,%rax
and    $0x1,%rax
add    $0x30,%rax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    118e <main+0x6e>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1157 <main+0x37>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x8(%rsi),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%r14d
lea    0x1(%r14),%r15
jmp    116c <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r12
mov    %r12,%rax
mov    %r14d,%ecx
shr    %cl,%rax
test   %rax,%rax
jne    11a1 <main+0x81>
test   %r14d,%r14d
jle    1150 <main+0x30>
mov    %r12,%r13
shr    %r13
xor    %r12,%r13
mov    %r15,%rbx
nopl   (%rax)
lea    -0x2(%rbx),%ecx
mov    %r13,%rax
shr    %cl,%rax
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jg     1180 <main+0x60>
jmp    1150 <main+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strtol(i8* %12, i32* null, i32 10)
store i32 %13, i32* %6
store i64 0, i64* %7
br label %14
14: ; preds = %44, %2
%15 = load i64, i64* %7
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = shl i64 1, %17
%19 = icmp ult i64 %15, %18
br i1 %19, label %20, label %47
20: ; preds = %14
%21 = load i64, i64* %7
%22 = load i64, i64* %7
%23 = lshr i64 %22, 1
%24 = xor i64 %21, %23
store i64 %24, i64* %8
%25 = load i32, i32* %6
%26 = sub nsw i32 %25, 1
store i32 %26, i32* %9
br label %27
27: ; preds = %39, %20
%28 = load i32, i32* %9
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i64, i64* %8
%32 = load i32, i32* %9
%33 = zext i32 %32 to i64
%34 = lshr i64 %31, %33
%35 = and i64 %34, 1
%36 = add i64 48, %35
%37 = trunc i64 %36 to i8
%38 = call i32 @putchar(i8 signext %37)
br label %39
39: ; preds = %30
%40 = load i32, i32* %9
%41 = add nsw i32 %40, -1
store i32 %41, i32* %9
br label %27
42: ; preds = %27
%43 = call i32 @putchar(i8 signext 10)
br label %44
44: ; preds = %42
%45 = load i64, i64* %7
%46 = add i64 %45, 1
store i64 %46, i64* %7
br label %14
47: ; preds = %14
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = zext i32 %5 to i64
%7 = icmp sgt i32 %5, 0
br label %9
8: ; preds = %13
ret i32 0
9: ; preds = %2, %13
%10 = phi i64 [ 0, %2 ], [ %15, %13 ]
%11 = lshr i64 %10, 1
%12 = xor i64 %11, %10
br i1 %7, label %18, label %13
13: ; preds = %18, %9
%14 = tail call i32 @putchar(i8 signext 10)
%15 = add i64 %10, 1
%16 = lshr i64 %15, %6
%17 = icmp eq i64 %16, 0
br i1 %17, label %9, label %8
18: ; preds = %9, %18
%19 = phi i64 [ %20, %18 ], [ %6, %9 ]
%20 = add nsw i64 %19, -1
%21 = and i64 %20, 4294967295
%22 = lshr i64 %12, %21
%23 = trunc i64 %22 to i8
%24 = and i8 %23, 1
%25 = or i8 %24, 48
%26 = tail call i32 @putchar(i8 signext %25)
%27 = icmp sgt i64 %19, 1
br i1 %27, label %18, label %13
}