#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 */
typedef int int32_t;

/* Variables and functions */
char *format_string(char *);
int /*<<< orphan*/ report_error(char *);
int /*<<< orphan*/ store(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void process_string(char *str) {
  int32_t *int_ptr;
  char aligned_str[1000];
  int32_t ii;
  str = format_string(str);
  if (str == NULL) {
    report_error("Invalid string format");
    return;
  }
  strcpy(aligned_str, str);
  int_ptr = (int32_t *)aligned_str;
  int str_len = (strlen(aligned_str) + sizeof(int32_t)) / sizeof(int32_t);
  for (ii = 0; ii < str_len; ii++) {
    store(int_ptr[ii]);
  }
}


x86 assembly (clang, -O0):
<process_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <format_string@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1188 <process_string+0x38>
lea    0xe82(%rip),%rdi
call   1060 <report_error@plt>
jmp    1202 <process_string+0xb2>
lea    -0x400(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x400(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x400(%rbp),%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
shr    $0x2,%rax
mov    %eax,-0x408(%rbp)
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
cmp    -0x408(%rbp),%eax
jge    1202 <process_string+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x404(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <store@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    11c9 <process_string+0x79>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_string>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
call   1070 <format_string@plt>
test   %rax,%rax
je     11ac <process_string+0x5c>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
add    $0x4,%rax
shr    $0x2,%rax
test   %eax,%eax
jle    11a1 <process_string+0x51>
mov    %eax,%r14d
xor    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,4),%edi
call   1030 <store@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1190 <process_string+0x40>
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe4d(%rip),%rdi
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <report_error@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Invalid string format\00"
define void @process_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @format_string(i8* %7)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @report_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %39
13: ; preds = %1
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%18 = bitcast i8* %17 to i32*
store i32* %18, i32** %3
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sext i32 %20 to i64
%22 = add i64 %21, 4
%23 = udiv i64 %22, 4
%24 = trunc i64 %23 to i32
store i32 %24, i32* %6
store i32 0, i32* %5
br label %25
25: ; preds = %36, %13
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32*, i32** %3
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @store(i32 %34)
br label %36
36: ; preds = %29
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %25
39: ; preds = %11, %25
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Invalid string format\00"
define void @process_string(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @format_string(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @report_error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %1
%9 = call i32 @strcpy(i8* %3, i8* %4)
%10 = bitcast [1000 x i8]* %2 to i32*
%11 = call i32 @strlen(i8* %3)
%12 = sext i32 %11 to i64
%13 = add nsw i64 %12, 4
%14 = lshr i64 %13, 2
%15 = trunc i64 %14 to i32
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %8
%18 = and i64 %14, 4294967295
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %24, %19 ]
%21 = getelementptr inbounds i32, i32* %10, i64 %20
%22 = load i32, i32* %21
%23 = call i32 @store(i32 %22)
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %18
br i1 %25, label %26, label %19
26: ; preds = %19, %8, %6
ret void
}