#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*/ Fatal_Error(char *, char const *);
char *Scan_Long(char const *, long *);
int strlen(char const *);
char Get_Format_Char(const char *format, int i) {
  long size;
  format = Scan_Long(format, &size);
  if (!*format)
    Fatal_Error("bad format: %s", format);
  if (i >= (int)strlen(format))
    i = strlen(format) - 1;
  return format[i];
}


x86 assembly (clang, -O0):
<Get_Format_Char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <Scan_Long@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    116d <Get_Format_Char+0x3d>
mov    -0x8(%rbp),%rsi
lea    0xe98(%rip),%rdi
call   1050 <Fatal_Error@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jl     1198 <Get_Format_Char+0x68>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Get_Format_Char>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rsp,%rsi
call   1030 <Scan_Long@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
jne    1154 <Get_Format_Char+0x24>
lea    0xeb4(%rip),%rdi
mov    %rbx,%rsi
call   1050 <Fatal_Error@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %ebp,%eax
jg     116d <Get_Format_Char+0x3d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
movslq %ebp,%rax
mov    (%rbx,%rax,1),%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"bad format: %s\00"
define signext i8 @Get_Format_Char(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i8* @Scan_Long(i8* %6, i64* %5)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call i32 @Fatal_Error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %2
%15 = load i32, i32* %4
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp sge i32 %15, %17
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %4
br label %23
23: ; preds = %19, %14
%24 = load i8*, i8** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
ret i8 %28
}

LLVM IR (-O2):
@.str = [15 x i8] c"bad format: %s\00"
define signext i8 @Get_Format_Char(i8* %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i8* @Scan_Long(i8* %0, i64* %3)
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @Fatal_Error(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %10
10: ; preds = %8, %2
%11 = call i32 @strlen(i8* %5)
%12 = icmp sgt i32 %11, %1
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i32 @strlen(i8* %5)
%15 = add nsw i32 %14, -1
br label %16
16: ; preds = %13, %10
%17 = phi i32 [ %15, %13 ], [ %1, %10 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %5, i64 %18
%20 = load i8, i8* %19
ret i8 %20
}