#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 */
char *concat(char *, char *);
char *gen_cond_goto(char *, char *);
char *gen_goto(char *);
scalar_t__ malloc(int);
char *newlabel();
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
char *gen_while(char *expr_code, char *expr, char *statements) {
  char *result;
  char *label1 = newlabel();
  char *label2 = newlabel();
  char *label3 = newlabel();
  result = (char *)malloc((strlen(label1) + 1) * (sizeof(char)));
  sprintf(result, "%s:\n", label1);
  result = concat(result, expr_code);
  result = concat(result, gen_cond_goto(label2, expr));
  result = concat(result, gen_goto(label3));
  result = concat(result, label2);
  result = concat(result, ":\n");
  result = concat(result, statements);
  result = concat(result, gen_goto(label1));
  result = concat(result, label3);
  result = concat(result, ":\n");
  return result;
}


x86 assembly (clang, -O0):
<gen_while>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1050 <newlabel@plt>
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <newlabel@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <newlabel@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe2f(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <gen_cond_goto@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <gen_goto@plt>
mov    -0x48(%rbp),%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <gen_goto@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd62(%rip),%rsi
call   1060 <concat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_while>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbp
xor    %eax,%eax
call   1050 <newlabel@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <newlabel@plt>
mov    %rax,%r12
xor    %eax,%eax
call   1050 <newlabel@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe43(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <concat@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <gen_cond_goto@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,%rbp
mov    %r15,%rdi
call   1080 <gen_goto@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <concat@plt>
lea    0xdee(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <concat@plt>
mov    %rax,%rdi
mov    (%rsp),%rsi
call   1060 <concat@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1080 <gen_goto@plt>
mov    %rbp,%rdi
mov    %rax,%rsi
call   1060 <concat@plt>
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <concat@plt>
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <concat@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [3 x i8] c":\0A\00"
define i8* @gen_while(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = call i8* (...) @newlabel()
store i8* %11, i8** %8
%12 = call i8* (...) @newlabel()
store i8* %12, i8** %9
%13 = call i8* (...) @newlabel()
store i8* %13, i8** %10
%14 = load i8*, i8** %8
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = load i8*, i8** %8
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = call i8* @concat(i8* %25, i8* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = load i8*, i8** %9
%30 = load i8*, i8** %5
%31 = call i8* @gen_cond_goto(i8* %29, i8* %30)
%32 = call i8* @concat(i8* %28, i8* %31)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = load i8*, i8** %10
%35 = call i8* @gen_goto(i8* %34)
%36 = call i8* @concat(i8* %33, i8* %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = load i8*, i8** %9
%39 = call i8* @concat(i8* %37, i8* %38)
store i8* %39, i8** %7
%40 = load i8*, i8** %7
%41 = call i8* @concat(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = load i8*, i8** %6
%44 = call i8* @concat(i8* %42, i8* %43)
store i8* %44, i8** %7
%45 = load i8*, i8** %7
%46 = load i8*, i8** %8
%47 = call i8* @gen_goto(i8* %46)
%48 = call i8* @concat(i8* %45, i8* %47)
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = load i8*, i8** %10
%51 = call i8* @concat(i8* %49, i8* %50)
store i8* %51, i8** %7
%52 = load i8*, i8** %7
%53 = call i8* @concat(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %7
%54 = load i8*, i8** %7
ret i8* %54
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s:\0A\00"
@.str.1 = [3 x i8] c":\0A\00"
define i8* @gen_while(i8* %0, i8* %1, i8* %2) {
%4 = tail call i8* (...) @newlabel()
%5 = tail call i8* (...) @newlabel()
%6 = tail call i8* (...) @newlabel()
%7 = tail call i32 @strlen(i8* %4)
%8 = add nsw i32 %7, 1
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4)
%12 = tail call i8* @concat(i8* %10, i8* %0)
%13 = tail call i8* @gen_cond_goto(i8* %5, i8* %1)
%14 = tail call i8* @concat(i8* %12, i8* %13)
%15 = tail call i8* @gen_goto(i8* %6)
%16 = tail call i8* @concat(i8* %14, i8* %15)
%17 = tail call i8* @concat(i8* %16, i8* %5)
%18 = tail call i8* @concat(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i8* @concat(i8* %18, i8* %2)
%20 = tail call i8* @gen_goto(i8* %4)
%21 = tail call i8* @concat(i8* %19, i8* %20)
%22 = tail call i8* @concat(i8* %21, i8* %6)
%23 = tail call i8* @concat(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
ret i8* %23
}