#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 atoi(char *);
int /*<<< orphan*/ printf(char *, char *);
void add(char *v, char *digits, int n_digits, int position, int max) {
  if (position == max) {
    v[position] = '\0';
    if (atoi(v) % 7 == 0)
      printf("%s\n", v);
  } else {
    int i;
    for (i = 0; i < n_digits; i++) {
      v[position] = digits[i];
      add(v, digits, n_digits, position + 1, max);
    }
  }
}


x86 assembly (clang, -O0):
<add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1191 <add+0x61>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
mov    $0x7,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118c <add+0x5c>
mov    -0x8(%rbp),%rsi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
jmp    11e7 <add+0xb7>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e2 <add+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    -0x1c(%rbp),%r8d
call   1030 <add@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1198 <add+0x68>
jmp    11e7 <add+0xb7>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %edx,0xc(%rsp)
mov    %rdi,%rbx
cmp    %r8d,%ecx
jne    118b <add+0x5b>
movslq %r12d,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1050 <atoi@plt>
imul   $0xb6db6db7,%eax,%eax
add    $0x12492492,%eax
cmp    $0x24924924,%eax
ja     11dc <add+0xac>
lea    0xe8b(%rip),%rdi
mov    %rbx,%rsi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11dc <add+0xac>
mov    %r8d,%r13d
mov    %rsi,%rbp
movslq %r12d,%rax
mov    %rax,0x10(%rsp)
add    $0x1,%r12d
mov    0xc(%rsp),%r14d
xor    %r15d,%r15d
nopl   0x0(%rax)
movzbl 0x0(%rbp,%r15,1),%eax
mov    0x10(%rsp),%rcx
mov    %al,(%rbx,%rcx,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    0xc(%rsp),%edx
mov    %r12d,%ecx
mov    %r13d,%r8d
call   1030 <add@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    11b0 <add+0x80>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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