#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 script_section {
  int dummy;
};
struct script {
  int dummy;
};
typedef int /*<<< orphan*/ sections;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ generate_dram_struct(int /*<<< orphan*/ *,
                                        struct script_section *);
struct script_section *script_find_section(struct script *, char const *);
int /*<<< orphan*/ stderr;
int script_generate_uboot(FILE *out,
                          const char *UNUSED_filename __attribute__((unused)),
                          struct script *script) {
  struct {
    const char *name;
    struct script_section *sp;
  } sections[] = {
      {"dram_para", NULL},
  };
  for (unsigned i = 0; i < (sizeof(sections) / sizeof((sections)[0])); i++) {
    struct script_section *sp;
    sp = script_find_section(script, sections[i].name);
    if (sp)
      sections[i].sp = sp;
    else {
      fprintf(stderr,
              "E: fexc-uboot: "
              "%s: critical section missing",
              sections[i].name);
      return 0;
    }
  }
  fputs("/* this file is generated, don't edit it yourself */\n\n"
        "#include <common.h>\n"
        "#include <asm/arch/dram.h>\n\n",
        out);
  generate_dram_struct(out, sections[0].sp);
  return 1;
}


x86 assembly (clang, -O0):
<script_generate_uboot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2ca5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ca2(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    $0x1,%rax
jae    120d <script_generate_uboot+0xcd>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
call   1050 <script_find_section@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11c6 <script_generate_uboot+0x86>
mov    -0x40(%rbp),%rcx
mov    -0x34(%rbp),%eax
mov    %eax,%edx
lea    -0x30(%rbp),%rax
shl    $0x4,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
jmp    11fa <script_generate_uboot+0xba>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
lea    -0x30(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%rdx
lea    0xe21(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1231 <script_generate_uboot+0xf1>
jmp    11ff <script_generate_uboot+0xbf>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1171 <script_generate_uboot+0x31>
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <generate_dram_struct@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<script_generate_uboot>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
mov    %rdx,%rdi
call   1040 <script_find_section@plt>
test   %rax,%rax
je     1189 <script_generate_uboot+0x49>
mov    %rax,%rbx
lea    0xed1(%rip),%rdi
mov    $0x66,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <generate_dram_struct@plt>
mov    $0x1,%eax
jmp    11a7 <script_generate_uboot+0x67>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
lea    0xe60(%rip),%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.anon = type { i8*, %struct.script_section* }
%struct.script_section = type { i32 }
%struct.script = type { i32 }
@.str = [10 x i8] c"dram_para\00"
@__const.script_generate_uboot.sections = [1 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), %struct.script_section* null }]
@stderr = global i32 0
@.str.1 = [44 x i8] c"E: fexc-uboot: %s: critical section missing\00"
@.str.2 = [103 x i8] c"/* this file is generated, don't edit it yourself */\0A\0A#include <common.h>\0A#include <asm/arch/dram.h>\0A\0A\00"
define i32 @script_generate_uboot(i32* %0, i8* %1, %struct.script* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.script*
%8 = alloca [1 x %struct.anon]
%9 = alloca i32
%10 = alloca %struct.script_section*
store i32* %0, i32** %5
store i8* %1, i8** %6
store %struct.script* %2, %struct.script** %7
%11 = bitcast [1 x %struct.anon]* %8 to i8*
store i32 0, i32* %9
br label %12
12: ; preds = %41, %3
%13 = load i32, i32* %9
%14 = zext i32 %13 to i64
%15 = icmp ult i64 %14, 1
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = load %struct.script*, %struct.script** %7
%18 = load i32, i32* %9
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* %8, i64 0, i64 %19
%21 = getelementptr inbounds %struct.anon, %struct.anon* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call %struct.script_section* @script_find_section(%struct.script* %17, i8* %22)
store %struct.script_section* %23, %struct.script_section** %10
%24 = load %struct.script_section*, %struct.script_section** %10
%25 = icmp ne %struct.script_section* %24, null
br i1 %25, label %26, label %32
26: ; preds = %16
%27 = load %struct.script_section*, %struct.script_section** %10
%28 = load i32, i32* %9
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* %8, i64 0, i64 %29
%31 = getelementptr inbounds %struct.anon, %struct.anon* %30, i32 0, i32 1
store %struct.script_section* %27, %struct.script_section** %31
br label %40
32: ; preds = %16
%33 = load i32, i32* @stderr
%34 = load i32, i32* %9
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* %8, i64 0, i64 %35
%37 = getelementptr inbounds %struct.anon, %struct.anon* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %38)
store i32 0, i32* %4
br label %52
40: ; preds = %26
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add i32 %42, 1
store i32 %43, i32* %9
br label %12
44: ; preds = %12
%45 = load i32*, i32** %5
%46 = call i32 @fputs(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), i32* %45)
%47 = load i32*, i32** %5
%48 = getelementptr inbounds [1 x %struct.anon], [1 x %struct.anon]* %8, i64 0, i64 0
%49 = getelementptr inbounds %struct.anon, %struct.anon* %48, i32 0, i32 1
%50 = load %struct.script_section*, %struct.script_section** %49
%51 = call i32 @generate_dram_struct(i32* %47, %struct.script_section* %50)
store i32 1, i32* %4
br label %52
52: ; preds = %44, %32
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
%struct.script = type { i32 }
%struct.script_section = type { i32 }
@.str = [10 x i8] c"dram_para\00"
@stderr = global i32 0
@.str.1 = [44 x i8] c"E: fexc-uboot: %s: critical section missing\00"
@.str.2 = [103 x i8] c"/* this file is generated, don't edit it yourself */\0A\0A#include <common.h>\0A#include <asm/arch/dram.h>\0A\0A\00"
define i32 @script_generate_uboot(i32* %0, i8* nocapture readnone %1, %struct.script* %2) {
%4 = tail call %struct.script_section* @script_find_section(%struct.script* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq %struct.script_section* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %3
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str.2, i64 0, i64 0), i64 102, i64 1, i32* %0)
%11 = tail call i32 @generate_dram_struct(i32* %0, %struct.script_section* %4)
br label %12
12: ; preds = %6, %9
%13 = phi i32 [ 1, %9 ], [ 0, %6 ]
ret i32 %13
}