#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*/ ExpansionRom_SetActiveState(int, int);
scalar_t__ GenericInterface_LoadRom(int, char *);
int Settings_GetInt(char *);
char *Settings_GetString(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
void GenericInterface_RestoreRomSettings(void) {
  int i;
  for (i = 1; i < 17; i++) {
    char SettingsKey[32];
    char *pCurrentRomFilename;
    sprintf(SettingsKey, "sRom%2d", i);
    pCurrentRomFilename = Settings_GetString(SettingsKey);
    if (pCurrentRomFilename != 0) {
      if (strlen(pCurrentRomFilename) != 0) {
        if (GenericInterface_LoadRom(i, pCurrentRomFilename)) {
          int ActiveFlag;
          sprintf(SettingsKey, "iRom%2dActive", i);
          ActiveFlag = Settings_GetInt(SettingsKey);
          if (ActiveFlag != 0) {
            ExpansionRom_SetActiveState(i, (1 == 1));
          } else {
            ExpansionRom_SetActiveState(i, (1 == 0));
          }
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<GenericInterface_RestoreRomSettings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x1,-0x4(%rbp)
cmpl   $0x11,-0x4(%rbp)
jge    1234 <GenericInterface_RestoreRomSettings+0xd4>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe79(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1050 <Settings_GetString@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1221 <GenericInterface_RestoreRomSettings+0xc1>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
je     121c <GenericInterface_RestoreRomSettings+0xbc>
mov    -0x4(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1070 <GenericInterface_LoadRom@plt>
cmp    $0x0,%rax
je     1217 <GenericInterface_RestoreRomSettings+0xb7>
lea    -0x30(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe2d(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <Settings_GetInt@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     1208 <GenericInterface_RestoreRomSettings+0xa8>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1060 <ExpansionRom_SetActiveState@plt>
jmp    1212 <GenericInterface_RestoreRomSettings+0xb2>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1060 <ExpansionRom_SetActiveState@plt>
jmp    1217 <GenericInterface_RestoreRomSettings+0xb7>
jmp    121c <GenericInterface_RestoreRomSettings+0xbc>
jmp    1221 <GenericInterface_RestoreRomSettings+0xc1>
jmp    1226 <GenericInterface_RestoreRomSettings+0xc6>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116f <GenericInterface_RestoreRomSettings+0xf>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenericInterface_RestoreRomSettings>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    $0x1,%ebx
lea    0xe99(%rip),%r14
mov    %rsp,%r15
lea    0xe97(%rip),%r12
jmp    1188 <GenericInterface_RestoreRomSettings+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebx
cmp    $0x11,%ebx
je     11dc <GenericInterface_RestoreRomSettings+0x8c>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1040 <Settings_GetString@plt>
test   %rax,%rax
je     1180 <GenericInterface_RestoreRomSettings+0x30>
cmpb   $0x0,(%rax)
je     1180 <GenericInterface_RestoreRomSettings+0x30>
mov    %ebx,%edi
mov    %rax,%rsi
call   1060 <GenericInterface_LoadRom@plt>
test   %rax,%rax
je     1180 <GenericInterface_RestoreRomSettings+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1030 <Settings_GetInt@plt>
xor    %esi,%esi
test   %eax,%eax
setne  %sil
mov    %ebx,%edi
call   1050 <ExpansionRom_SetActiveState@plt>
jmp    1180 <GenericInterface_RestoreRomSettings+0x30>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"sRom%2d\00"
@.str.1 = [14 x i8] c"iRom%2dActive\00"
define void @GenericInterface_RestoreRomSettings() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca i8*
%4 = alloca i32
store i32 1, i32* %1
br label %5
5: ; preds = %43, %0
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 17
br i1 %7, label %8, label %46
8: ; preds = %5
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%10 = load i32, i32* %1
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%13 = call i8* @Settings_GetString(i8* %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %42
16: ; preds = %8
%17 = load i8*, i8** %3
%18 = call i64 @strlen(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load i32, i32* %1
%22 = load i8*, i8** %3
%23 = call i64 @GenericInterface_LoadRom(i32 %21, i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %40
25: ; preds = %20
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%27 = load i32, i32* %1
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%30 = call i32 @Settings_GetInt(i8* %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i32, i32* %1
%35 = call i32 @ExpansionRom_SetActiveState(i32 %34, i32 1)
br label %39
36: ; preds = %25
%37 = load i32, i32* %1
%38 = call i32 @ExpansionRom_SetActiveState(i32 %37, i32 0)
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %20
br label %41
41: ; preds = %40, %16
br label %42
42: ; preds = %41, %8
br label %43
43: ; preds = %42
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
br label %5
46: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"sRom%2d\00"
@.str.1 = [14 x i8] c"iRom%2dActive\00"
define void @GenericInterface_RestoreRomSettings() {
%1 = alloca [32 x i8]
%2 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %20
%4 = phi i32 [ 1, %0 ], [ %21, %20 ]
%5 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i8* @Settings_GetString(i8* %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %3
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = call i64 @GenericInterface_LoadRom(i32 %4, i8* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%16 = call i32 @Settings_GetInt(i8* %2)
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @ExpansionRom_SetActiveState(i32 %4, i32 %18)
br label %20
20: ; preds = %14, %8, %11, %3
%21 = add nuw nsw i32 %4, 1
%22 = icmp eq i32 %21, 17
br i1 %22, label %23, label %3
23: ; preds = %20
ret void
}