void _reset(void) {
  int i;
  extern char _data_start[];
  extern char _data_load_start[];
  extern char _data_size[];
  extern char _bss_start[];
  extern char _bss_size[];
  extern int main(void);
  for (i = 0; i < (int)_data_size; i++)
    _data_start[i] = _data_load_start[i];
  for (i = 0; i < (int)_bss_size; i++)
    _bss_start[i] = 0;
  main();
  while (1)
    ;
}


x86 assembly (clang, -O0):
<_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
cmp    %eax,-0x4(%rbp)
jge    1159 <_reset+0x49>
movslq -0x4(%rbp),%rcx
mov    0x2e7e(%rip),%rax
mov    (%rax,%rcx,1),%dl
movslq -0x4(%rbp),%rcx
mov    0x2ea0(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <_reset+0xf>
movl   $0x0,-0x4(%rbp)
mov    0x2e71(%rip),%rax
cmp    %eax,-0x4(%rbp)
jge    118d <_reset+0x7d>
movslq -0x4(%rbp),%rcx
mov    0x2e4d(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1160 <_reset+0x50>
call   1030 <main@plt>
jmp    1192 <_reset+0x82>

x86 assembly (clang, -O2):
<_reset>:
push   %rax
cmpl   $0x0,0x2e98(%rip)
jle    115e <_reset+0x2e>
mov    0x2e90(%rip),%eax
cmp    $0x2,%eax
mov    $0x1,%edx
cmovge %eax,%edx
mov    0x2e96(%rip),%rdi
mov    0x2e5f(%rip),%rsi
call   1040 <memcpy@plt>
cmpl   $0x0,0x2e73(%rip)
jle    1186 <_reset+0x56>
mov    0x2e6b(%rip),%eax
cmp    $0x2,%eax
mov    $0x1,%edx
cmovge %eax,%edx
mov    0x2e49(%rip),%rdi
xor    %esi,%esi
call   1030 <memset@plt>
call   1050 <main@plt>
nopl   0x0(%rax,%rax,1)
jmp    1190 <_reset+0x60>

LLVM IR (-O0):
@_data_size = external global [0 x i8]
@_data_load_start = external global [0 x i8]
@_data_start = external global [0 x i8]
@_bss_size = external global [0 x i8]
@_bss_start = external global [0 x i8]
define void @_reset() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %13, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, ptrtoint ([0 x i8]* @_data_size to i32)
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = load i32, i32* %1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [0 x i8], [0 x i8]* @_data_load_start, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = load i32, i32* %1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [0 x i8], [0 x i8]* @_data_start, i64 0, i64 %11
store i8 %9, i8* %12
br label %13
13: ; preds = %5
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %2
16: ; preds = %2
store i32 0, i32* %1
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %1
%19 = icmp slt i32 %18, ptrtoint ([0 x i8]* @_bss_size to i32)
br i1 %19, label %20, label %27
20: ; preds = %17
%21 = load i32, i32* %1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [0 x i8], [0 x i8]* @_bss_start, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %20
%25 = load i32, i32* %1
%26 = add nsw i32 %25, 1
store i32 %26, i32* %1
br label %17
27: ; preds = %17
%28 = call i32 @main()
br label %29
29: ; preds = %27, %29
br label %29
}

LLVM IR (-O2):
@_data_size = external global [0 x i8]
@_data_load_start = external global [0 x i8]
@_data_start = external global [0 x i8]
@_bss_size = external global [0 x i8]
@_bss_start = external global [0 x i8]
define void @_reset() {
br i1 icmp sgt (i32 ptrtoint ([0 x i8]* @_data_size to i32), i32 0), label %1, label %4
1: ; preds = %0
%2 = call i32 @llvm.smax.i32(i32 ptrtoint ([0 x i8]* @_data_size to i32), i32 1)
%3 = zext i32 %2 to i64
br label %4
4: ; preds = %1, %0
br i1 icmp sgt (i32 ptrtoint ([0 x i8]* @_bss_size to i32), i32 0), label %5, label %8
5: ; preds = %4
%6 = call i32 @llvm.smax.i32(i32 ptrtoint ([0 x i8]* @_bss_size to i32), i32 1)
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %4
%9 = tail call i32 @main()
br label %10
10: ; preds = %10, %8
br label %10
}