#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*/ gen_arith_expr(unsigned int);
int /*<<< orphan*/ gen_test_expr(unsigned int);
int /*<<< orphan*/ gen_variable_expr();
int /*<<< orphan*/ printf(char *);
int rand();
void gen_expr(unsigned int level) {
  if (!level || rand() % 100 < 5) {
    gen_variable_expr();
    return;
  }
  if (rand() % 100 < 20) {
    printf("(");
    gen_test_expr(level);
    printf(" ? ");
    gen_expr(level);
    printf(" : ");
    gen_expr(level);
    printf(")");
    return;
  }
  gen_arith_expr(level);
}


x86 assembly (clang, -O0):
<gen_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     118d <gen_expr+0x2d>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x5,%edx
jge    1199 <gen_expr+0x39>
mov    $0x0,%al
call   1030 <gen_variable_expr@plt>
jmp    1206 <gen_expr+0xa6>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
cmp    $0x14,%edx
jge    11fe <gen_expr+0x9e>
lea    0xe48(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <gen_test_expr@plt>
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <gen_expr@plt>
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <gen_expr@plt>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
jmp    1206 <gen_expr+0xa6>
mov    -0x4(%rbp),%edi
call   1070 <gen_arith_expr@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_expr>:
push   %rbx
test   %edi,%edi
je     119e <gen_expr+0x2e>
mov    %edi,%ebx
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x4,%eax
jg     11a6 <gen_expr+0x36>
xor    %eax,%eax
pop    %rbx
jmp    1040 <gen_variable_expr@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x13,%eax
jg     120f <gen_expr+0x9f>
mov    $0x28,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1070 <gen_test_expr@plt>
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <gen_expr@plt>
lea    0xe0c(%rip),%rdi
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <gen_expr@plt>
mov    $0x29,%edi
pop    %rbx
jmp    1030 <putchar@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1080 <gen_arith_expr@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"(\00"
@.str.1 = [4 x i8] c" ? \00"
@.str.2 = [4 x i8] c" : \00"
@.str.3 = [2 x i8] c")\00"
define void @gen_expr(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ne i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = call i32 (...) @rand()
%7 = srem i32 %6, 100
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %11
9: ; preds = %5, %1
%10 = call i32 (...) @gen_variable_expr()
br label %27
11: ; preds = %5
%12 = call i32 (...) @rand()
%13 = srem i32 %12, 100
%14 = icmp slt i32 %13, 20
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = call i32 @gen_test_expr(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %2
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %27
24: ; preds = %11
%25 = load i32, i32* %2
%26 = call i32 @gen_arith_expr(i32 %25)
br label %27
27: ; preds = %24, %15, %9
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c" ? \00"
@.str.2 = [4 x i8] c" : \00"
define void @gen_expr(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %7, label %3
3: ; preds = %1
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 100
%6 = icmp slt i32 %5, 5
br i1 %6, label %7, label %9
7: ; preds = %3, %1
%8 = tail call i32 (...) @gen_variable_expr()
br label %13
9: ; preds = %3
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = icmp slt i32 %11, 20
br i1 %12, label %14, label %20
13: ; preds = %7, %20, %14
ret void
14: ; preds = %9
%15 = tail call i32 @putchar(i32 40)
%16 = tail call i32 @gen_test_expr(i32 %0)
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
tail call void @gen_expr(i32 %0)
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
tail call void @gen_expr(i32 %0)
%19 = tail call i32 @putchar(i32 41)
br label %13
20: ; preds = %9
%21 = tail call i32 @gen_arith_expr(i32 %0)
br label %13
}