#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*/ printf(char *, ...);
void subset(int A[], int n) {
  int i;
  for (i = 0; i < (1 << n); i++) {
    printf("{ ");
    int j;
    for (j = 0; j < n; j++) {
      if ((i & (1 << j)) > 0) {
        printf("%d ", A[j]);
      }
    }
    printf("}\n");
  }
}


x86 assembly (clang, -O0):
<subset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jge    11c0 <subset+0xb0>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <subset+0x94>
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jle    1191 <subset+0x81>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <subset+0x86>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <subset+0x42>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <subset+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<subset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,0x4(%rsp)
cmp    $0x1f,%esi
jne    1143 <subset+0x23>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rdi,%rbx
mov    $0x1,%eax
mov    $0x1,%r13d
mov    0x4(%rsp),%ecx
shl    %cl,%r13d
cmp    $0x2,%r13d
cmovl  %eax,%r13d
mov    %ecx,%r14d
lea    0xe99(%rip),%rbp
xor    %r12d,%r12d
jmp    1185 <subset+0x65>
nop
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%r12d
cmp    %r13d,%r12d
je     1134 <subset+0x14>
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0x4(%rsp)
jle    1170 <subset+0x50>
xor    %r15d,%r15d
jmp    11a9 <subset+0x89>
nop
add    $0x1,%r15
cmp    %r15,%r14
je     1170 <subset+0x50>
bt     %r15d,%r12d
jae    11a0 <subset+0x80>
mov    (%rbx,%r15,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <subset+0x80>

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

LLVM IR (-O2):
@.str = [3 x i8] c"{ \00"
@.str.1 = [4 x i8] c"%d \00"
@str = [2 x i8] c"}\00"
define void @subset(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 31
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = shl nuw nsw i32 1, %1
%6 = icmp sgt i32 %1, 0
%7 = call i32 @llvm.smax.i32(i32 %5, i32 1)
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %4, %25
%10 = phi i32 [ 0, %4 ], [ %27, %25 ]
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br i1 %6, label %12, label %25
12: ; preds = %9, %22
%13 = phi i64 [ %23, %22 ], [ 0, %9 ]
%14 = trunc i64 %13 to i32
%15 = shl nuw i32 1, %14
%16 = and i32 %15, %10
%17 = icmp eq i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = getelementptr inbounds i32, i32* %0, i64 %13
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %12, %18
%23 = add nuw nsw i64 %13, 1
%24 = icmp eq i64 %23, %8
br i1 %24, label %25, label %12
25: ; preds = %22, %9
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%27 = add nuw nsw i32 %10, 1
%28 = icmp eq i32 %27, %7
br i1 %28, label %29, label %9
29: ; preds = %25, %2
ret void
}