#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 */
struct statement {
  int dummy;
};
struct list {
  int dummy;
};
struct expression {
  int dummy;
};

/* Variables and functions */
struct list *list_new(int, struct statement const *, struct statement const *,
                      int /*<<< orphan*/ *);
struct statement *stmt_compound(struct list *);
struct statement const *stmt_expression(struct expression const *);
struct statement const *stmt_while(int /*<<< orphan*/, struct statement *);
int /*<<< orphan*/ to_boolean(struct expression const *);
struct statement *stmt_for(const struct expression *init,
                           const struct expression *cond,
                           const struct expression *next,
                           const struct statement *body) {
  struct list *body_stmts =
      list_new((1 << 1), body, stmt_expression(next), NULL);
  struct statement *body_compound = stmt_compound(body_stmts);
  struct list *li = list_new((1 << 1), stmt_expression(init),
                             stmt_while(to_boolean(cond), body_compound), NULL);
  return stmt_compound(li);
}


x86 assembly (clang, -O0):
<stmt_for>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <stmt_expression@plt>
mov    -0x48(%rbp),%rsi
mov    %rax,%rdx
mov    $0x2,%edi
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <list_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <stmt_compound@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <stmt_expression@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <to_boolean@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
call   1050 <stmt_while@plt>
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
mov    $0x2,%edi
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <list_new@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <stmt_compound@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stmt_for>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <stmt_expression@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1070 <list_new@plt>
mov    %rax,%rdi
call   1060 <stmt_compound@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <stmt_expression@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <to_boolean@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <stmt_while@plt>
mov    $0x2,%edi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1070 <list_new@plt>
mov    %rax,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <stmt_compound@plt>

LLVM IR (-O0):
%struct.expression = type { i32 }
%struct.statement = type { i32 }
%struct.list = type { i32 }
define %struct.statement* @stmt_for(%struct.expression* %0, %struct.expression* %1, %struct.expression* %2, %struct.statement* %3) {
%5 = alloca %struct.expression*
%6 = alloca %struct.expression*
%7 = alloca %struct.expression*
%8 = alloca %struct.statement*
%9 = alloca %struct.list*
%10 = alloca %struct.statement*
%11 = alloca %struct.list*
store %struct.expression* %0, %struct.expression** %5
store %struct.expression* %1, %struct.expression** %6
store %struct.expression* %2, %struct.expression** %7
store %struct.statement* %3, %struct.statement** %8
%12 = load %struct.statement*, %struct.statement** %8
%13 = load %struct.expression*, %struct.expression** %7
%14 = call %struct.statement* @stmt_expression(%struct.expression* %13)
%15 = call %struct.list* @list_new(i32 2, %struct.statement* %12, %struct.statement* %14, i32* null)
store %struct.list* %15, %struct.list** %9
%16 = load %struct.list*, %struct.list** %9
%17 = call %struct.statement* @stmt_compound(%struct.list* %16)
store %struct.statement* %17, %struct.statement** %10
%18 = load %struct.expression*, %struct.expression** %5
%19 = call %struct.statement* @stmt_expression(%struct.expression* %18)
%20 = load %struct.expression*, %struct.expression** %6
%21 = call i32 @to_boolean(%struct.expression* %20)
%22 = load %struct.statement*, %struct.statement** %10
%23 = call %struct.statement* @stmt_while(i32 %21, %struct.statement* %22)
%24 = call %struct.list* @list_new(i32 2, %struct.statement* %19, %struct.statement* %23, i32* null)
store %struct.list* %24, %struct.list** %11
%25 = load %struct.list*, %struct.list** %11
%26 = call %struct.statement* @stmt_compound(%struct.list* %25)
ret %struct.statement* %26
}

LLVM IR (-O2):
%struct.expression = type { i32 }
%struct.statement = type { i32 }
%struct.list = type { i32 }
define %struct.statement* @stmt_for(%struct.expression* %0, %struct.expression* %1, %struct.expression* %2, %struct.statement* %3) {
%5 = tail call %struct.statement* @stmt_expression(%struct.expression* %2)
%6 = tail call %struct.list* @list_new(i32 2, %struct.statement* %3, %struct.statement* %5, i32* null)
%7 = tail call %struct.statement* @stmt_compound(%struct.list* %6)
%8 = tail call %struct.statement* @stmt_expression(%struct.expression* %0)
%9 = tail call i32 @to_boolean(%struct.expression* %1)
%10 = tail call %struct.statement* @stmt_while(i32 %9, %struct.statement* %7)
%11 = tail call %struct.list* @list_new(i32 2, %struct.statement* %8, %struct.statement* %10, i32* null)
%12 = tail call %struct.statement* @stmt_compound(%struct.list* %11)
ret %struct.statement* %12
}