#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 */
struct ber *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  struct ber {
    int num;
    struct ber *next;
  };
  int n = 10, m, k = 1;
  struct ber *p, *q, *head;
  head = q = malloc(sizeof(struct ber));
  for (m = 0; m < n - 1; m++) {
    p = malloc(sizeof(struct ber));
    q->next = p;
    q = p;
  }
  p->next = head;
  p = head;
  for (m = 1; m < 10; m++) {
    p->num = 1;
    p = p->next;
  }
  p = head;
  while (n > 1) {
    if (k % 3 == 0) {
      p->num = 0;
      n--;
    }
    k++;
    p = p->next;
  }
  for (m = 0; m < 10; m++) {
    if (p->num != 0)
      printf("%d", p->num);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xa,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1197 <main+0x77>
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <main+0x36>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11e0 <main+0xc0>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b2 <main+0x92>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1233 <main+0x113>
mov    -0x10(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1219 <main+0xf9>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11e8 <main+0xc8>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    1276 <main+0x156>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
je     1263 <main+0x143>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xda2(%rip),%rdi
call   1030 <printf@plt>
jmp    1268 <main+0x148>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123a <main+0x11a>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x10(%rsp)
mov    %rax,0x8(%rbx)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x8(%rsp)
mov    %rax,0x8(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rax,(%rsp)
mov    %rax,0x8(%r14)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r13
mov    %rax,0x8(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
mov    %rax,0x8(%r13)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,0x8(%rbp)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x8(%r14)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x8(%r15)
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%r12)
mov    %rbx,0x8(%rax)
movl   $0x1,(%rbx)
mov    0x10(%rsp),%rax
movl   $0x1,(%rax)
mov    0x8(%rsp),%rax
movl   $0x1,(%rax)
mov    (%rsp),%rax
movl   $0x1,(%rax)
movl   $0x1,0x0(%r13)
movl   $0x1,0x0(%rbp)
movl   $0x1,(%r14)
movl   $0x1,(%r15)
movl   $0x1,(%r12)
mov    $0x1,%eax
mov    $0xa,%ecx
mov    $0xffffffff,%edx
mov    $0xaaaaaaab,%esi
jmp    125f <main+0x13f>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%eax
mov    0x8(%rbx),%rbx
add    $0xffffffff,%edx
cmp    $0x1,%ecx
jle    127b <main+0x15b>
mov    %eax,%edi
imul   %rsi,%rdi
shr    $0x21,%rdi
lea    (%rdi,%rdi,2),%edi
add    %edx,%edi
jne    1250 <main+0x130>
movl   $0x0,(%rbx)
add    $0xffffffff,%ecx
jmp    1250 <main+0x130>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd74(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd5e(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd48(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd36(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd24(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd12(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xd00(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xcee(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xcdc(%rip),%rdi
call   1030 <printf@plt>
mov    (%rbx),%esi
test   %esi,%esi
je     133b <main+0x21b>
lea    0xcca(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ber = type { i32, %struct.ber* }
%struct.ber.0 = type opaque
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.ber*
%6 = alloca %struct.ber*
%7 = alloca %struct.ber*
store i32 0, i32* %1
store i32 10, i32* %2
store i32 1, i32* %4
%8 = call %struct.ber.0* @malloc(i32 16)
%9 = bitcast %struct.ber.0* %8 to %struct.ber*
store %struct.ber* %9, %struct.ber** %6
store %struct.ber* %9, %struct.ber** %7
store i32 0, i32* %3
br label %10
10: ; preds = %22, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = sub nsw i32 %12, 1
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = call %struct.ber.0* @malloc(i32 16)
%17 = bitcast %struct.ber.0* %16 to %struct.ber*
store %struct.ber* %17, %struct.ber** %5
%18 = load %struct.ber*, %struct.ber** %5
%19 = load %struct.ber*, %struct.ber** %6
%20 = getelementptr inbounds %struct.ber, %struct.ber* %19, i32 0, i32 1
store %struct.ber* %18, %struct.ber** %20
%21 = load %struct.ber*, %struct.ber** %5
store %struct.ber* %21, %struct.ber** %6
br label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %10
25: ; preds = %10
%26 = load %struct.ber*, %struct.ber** %7
%27 = load %struct.ber*, %struct.ber** %5
%28 = getelementptr inbounds %struct.ber, %struct.ber* %27, i32 0, i32 1
store %struct.ber* %26, %struct.ber** %28
%29 = load %struct.ber*, %struct.ber** %7
store %struct.ber* %29, %struct.ber** %5
store i32 1, i32* %3
br label %30
30: ; preds = %39, %25
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 10
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = load %struct.ber*, %struct.ber** %5
%35 = getelementptr inbounds %struct.ber, %struct.ber* %34, i32 0, i32 0
store i32 1, i32* %35
%36 = load %struct.ber*, %struct.ber** %5
%37 = getelementptr inbounds %struct.ber, %struct.ber* %36, i32 0, i32 1
%38 = load %struct.ber*, %struct.ber** %37
store %struct.ber* %38, %struct.ber** %5
br label %39
39: ; preds = %33
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %30
42: ; preds = %30
%43 = load %struct.ber*, %struct.ber** %7
store %struct.ber* %43, %struct.ber** %5
br label %44
44: ; preds = %56, %42
%45 = load i32, i32* %2
%46 = icmp sgt i32 %45, 1
br i1 %46, label %47, label %62
47: ; preds = %44
%48 = load i32, i32* %4
%49 = srem i32 %48, 3
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load %struct.ber*, %struct.ber** %5
%53 = getelementptr inbounds %struct.ber, %struct.ber* %52, i32 0, i32 0
store i32 0, i32* %53
%54 = load i32, i32* %2
%55 = add nsw i32 %54, -1
store i32 %55, i32* %2
br label %56
56: ; preds = %51, %47
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
%59 = load %struct.ber*, %struct.ber** %5
%60 = getelementptr inbounds %struct.ber, %struct.ber* %59, i32 0, i32 1
%61 = load %struct.ber*, %struct.ber** %60
store %struct.ber* %61, %struct.ber** %5
br label %44
62: ; preds = %44
store i32 0, i32* %3
br label %63
63: ; preds = %77, %62
%64 = load i32, i32* %3
%65 = icmp slt i32 %64, 10
br i1 %65, label %66, label %80
66: ; preds = %63
%67 = load %struct.ber*, %struct.ber** %5
%68 = getelementptr inbounds %struct.ber, %struct.ber* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %66
%72 = load %struct.ber*, %struct.ber** %5
%73 = getelementptr inbounds %struct.ber, %struct.ber* %72, i32 0, i32 0
%74 = load i32, i32* %73
%75 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %71, %66
br label %77
77: ; preds = %76
%78 = load i32, i32* %3
%79 = add nsw i32 %78, 1
store i32 %79, i32* %3
br label %63
80: ; preds = %63
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
%struct.ber.0 = type opaque
%struct.ber = type { i32, %struct.ber* }
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = tail call %struct.ber.0* @malloc(i32 16)
%2 = bitcast %struct.ber.0* %1 to %struct.ber*
%3 = tail call %struct.ber.0* @malloc(i32 16)
%4 = bitcast %struct.ber.0* %3 to %struct.ber*
%5 = getelementptr inbounds %struct.ber, %struct.ber* %2, i64 0, i32 1
%6 = bitcast %struct.ber** %5 to %struct.ber.0**
store %struct.ber.0* %3, %struct.ber.0** %6
%7 = tail call %struct.ber.0* @malloc(i32 16)
%8 = bitcast %struct.ber.0* %7 to %struct.ber*
%9 = getelementptr inbounds %struct.ber, %struct.ber* %4, i64 0, i32 1
%10 = bitcast %struct.ber** %9 to %struct.ber.0**
store %struct.ber.0* %7, %struct.ber.0** %10
%11 = tail call %struct.ber.0* @malloc(i32 16)
%12 = bitcast %struct.ber.0* %11 to %struct.ber*
%13 = getelementptr inbounds %struct.ber, %struct.ber* %8, i64 0, i32 1
%14 = bitcast %struct.ber** %13 to %struct.ber.0**
store %struct.ber.0* %11, %struct.ber.0** %14
%15 = tail call %struct.ber.0* @malloc(i32 16)
%16 = bitcast %struct.ber.0* %15 to %struct.ber*
%17 = getelementptr inbounds %struct.ber, %struct.ber* %12, i64 0, i32 1
%18 = bitcast %struct.ber** %17 to %struct.ber.0**
store %struct.ber.0* %15, %struct.ber.0** %18
%19 = tail call %struct.ber.0* @malloc(i32 16)
%20 = bitcast %struct.ber.0* %19 to %struct.ber*
%21 = getelementptr inbounds %struct.ber, %struct.ber* %16, i64 0, i32 1
%22 = bitcast %struct.ber** %21 to %struct.ber.0**
store %struct.ber.0* %19, %struct.ber.0** %22
%23 = tail call %struct.ber.0* @malloc(i32 16)
%24 = bitcast %struct.ber.0* %23 to %struct.ber*
%25 = getelementptr inbounds %struct.ber, %struct.ber* %20, i64 0, i32 1
%26 = bitcast %struct.ber** %25 to %struct.ber.0**
store %struct.ber.0* %23, %struct.ber.0** %26
%27 = tail call %struct.ber.0* @malloc(i32 16)
%28 = bitcast %struct.ber.0* %27 to %struct.ber*
%29 = getelementptr inbounds %struct.ber, %struct.ber* %24, i64 0, i32 1
%30 = bitcast %struct.ber** %29 to %struct.ber.0**
store %struct.ber.0* %27, %struct.ber.0** %30
%31 = tail call %struct.ber.0* @malloc(i32 16)
%32 = bitcast %struct.ber.0* %31 to %struct.ber*
%33 = getelementptr inbounds %struct.ber, %struct.ber* %28, i64 0, i32 1
%34 = bitcast %struct.ber** %33 to %struct.ber.0**
store %struct.ber.0* %31, %struct.ber.0** %34
%35 = tail call %struct.ber.0* @malloc(i32 16)
%36 = getelementptr inbounds %struct.ber, %struct.ber* %32, i64 0, i32 1
%37 = bitcast %struct.ber** %36 to %struct.ber.0**
store %struct.ber.0* %35, %struct.ber.0** %37
%38 = bitcast %struct.ber.0* %35 to %struct.ber*
%39 = getelementptr inbounds %struct.ber, %struct.ber* %38, i64 0, i32 1
%40 = bitcast %struct.ber** %39 to %struct.ber.0**
store %struct.ber.0* %1, %struct.ber.0** %40
%41 = bitcast %struct.ber.0* %1 to i32*
store i32 1, i32* %41
%42 = bitcast %struct.ber.0* %3 to i32*
store i32 1, i32* %42
%43 = bitcast %struct.ber.0* %7 to i32*
store i32 1, i32* %43
%44 = bitcast %struct.ber.0* %11 to i32*
store i32 1, i32* %44
%45 = bitcast %struct.ber.0* %15 to i32*
store i32 1, i32* %45
%46 = bitcast %struct.ber.0* %19 to i32*
store i32 1, i32* %46
%47 = bitcast %struct.ber.0* %23 to i32*
store i32 1, i32* %47
%48 = bitcast %struct.ber.0* %27 to i32*
store i32 1, i32* %48
%49 = bitcast %struct.ber.0* %31 to i32*
store i32 1, i32* %49
br label %54
50: ; preds = %63
%51 = getelementptr inbounds %struct.ber, %struct.ber* %67, i64 0, i32 0
%52 = load i32, i32* %51
%53 = icmp eq i32 %52, 0
br i1 %53, label %107, label %69
54: ; preds = %0, %63
%55 = phi i32 [ %64, %63 ], [ 10, %0 ]
%56 = phi %struct.ber* [ %67, %63 ], [ %2, %0 ]
%57 = phi i32 [ %65, %63 ], [ 1, %0 ]
%58 = urem i32 %57, 3
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %54
%61 = getelementptr inbounds %struct.ber, %struct.ber* %56, i64 0, i32 0
store i32 0, i32* %61
%62 = add nsw i32 %55, -1
br label %63
63: ; preds = %60, %54
%64 = phi i32 [ %62, %60 ], [ %55, %54 ]
%65 = add nuw nsw i32 %57, 1
%66 = getelementptr inbounds %struct.ber, %struct.ber* %56, i64 0, i32 1
%67 = load %struct.ber*, %struct.ber** %66
%68 = icmp sgt i32 %64, 1
br i1 %68, label %54, label %50
69: ; preds = %50
%70 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %52)
%71 = load i32, i32* %51
%72 = icmp eq i32 %71, 0
br i1 %72, label %107, label %73
73: ; preds = %69
%74 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %71)
%75 = load i32, i32* %51
%76 = icmp eq i32 %75, 0
br i1 %76, label %107, label %77
77: ; preds = %73
%78 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %75)
%79 = load i32, i32* %51
%80 = icmp eq i32 %79, 0
br i1 %80, label %107, label %81
81: ; preds = %77
%82 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %79)
%83 = load i32, i32* %51
%84 = icmp eq i32 %83, 0
br i1 %84, label %107, label %85
85: ; preds = %81
%86 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %83)
%87 = load i32, i32* %51
%88 = icmp eq i32 %87, 0
br i1 %88, label %107, label %89
89: ; preds = %85
%90 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %87)
%91 = load i32, i32* %51
%92 = icmp eq i32 %91, 0
br i1 %92, label %107, label %93
93: ; preds = %89
%94 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %91)
%95 = load i32, i32* %51
%96 = icmp eq i32 %95, 0
br i1 %96, label %107, label %97
97: ; preds = %93
%98 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %95)
%99 = load i32, i32* %51
%100 = icmp eq i32 %99, 0
br i1 %100, label %107, label %101
101: ; preds = %97
%102 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %99)
%103 = load i32, i32* %51
%104 = icmp eq i32 %103, 0
br i1 %104, label %107, label %105
105: ; preds = %101
%106 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %103)
br label %107
107: ; preds = %50, %69, %73, %77, %81, %85, %89, %93, %97, %105, %101
ret i32 0
}