#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
size_t strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  char buffer[128] = {0};
  int overwrite[1] = {0};
  if (argc < 3) {
    printf("I need two arguments\n");
    printf("Usage: %s [overwrite index] [overwrite address]\n", argv[0]);
    return 1;
  }
  printf("Overwriting 0x%08x with 0x%08x\n",
         overwrite[strtoul(argv[1], NULL, 10)], strtoul(argv[2], NULL, 10));
  overwrite[strtoul(argv[1], NULL, 10)] = strtoul(argv[2], NULL, 10);
  printf("insert ropchain: ");
  fgets(buffer, 128, stdin);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x94(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
jge    11b8 <main+0x78>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1276 <main+0x136>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    -0x94(%rbp,%rax,4),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    -0x9c(%rbp),%esi
mov    %rax,%rdx
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x98(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    -0x98(%rbp),%ecx
mov    %ecx,-0x94(%rbp,%rax,4)
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rdi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1050 <fgets@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x2,%edi
jg     11a1 <main+0x61>
lea    0xee0(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rsi
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    121b <main+0xdb>
mov    0x8(%rbx),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
lea    0xe66(%rip),%rdi
xor    %esi,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    0x8(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1050 <fgets@plt>
mov    %r14d,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"I need two arguments\0A\00"
@.str.1 = [49 x i8] c"Usage: %s [overwrite index] [overwrite address]\0A\00"
@.str.2 = [32 x i8] c"Overwriting 0x%08x with 0x%08x\0A\00"
@.str.3 = [18 x i8] c"insert ropchain: \00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
%7 = alloca [1 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [128 x i8]* %6 to i8*
%9 = bitcast [1 x i32]* %7 to i8*
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %44
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i64 @strtoul(i8* %21, i32* null, i32 10)
%23 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i64 @strtoul(i8* %27, i32* null, i32 10)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %24, i64 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @strtoul(i8* %32, i32* null, i32 10)
%34 = trunc i64 %33 to i32
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i64 @strtoul(i8* %37, i32* null, i32 10)
%39 = getelementptr inbounds [1 x i32], [1 x i32]* %7, i64 0, i64 %38
store i32 %34, i32* %39
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %41, i32 128, i32 %42)
store i32 0, i32* %3
br label %44
44: ; preds = %18, %12
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str.1 = [49 x i8] c"Usage: %s [overwrite index] [overwrite address]\0A\00"
@.str.2 = [32 x i8] c"Overwriting 0x%08x with 0x%08x\0A\00"
@.str.3 = [18 x i8] c"insert ropchain: \00"
@stdin = global i32 0
@str = [21 x i8] c"I need two arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %25
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strtoul(i8* nocapture %12, i32* null, i32 10)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i64 @strtoul(i8* nocapture %15, i32* null, i32 10)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 0, i64 %16)
%18 = load i8*, i8** %14
%19 = tail call i64 @strtoul(i8* nocapture %18, i32* null, i32 10)
%20 = load i8*, i8** %11
%21 = tail call i64 @strtoul(i8* nocapture %20, i32* null, i32 10)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %4, i32 128, i32 %23)
br label %25
25: ; preds = %10, %6
%26 = phi i32 [ 1, %6 ], [ 0, %10 ]
ret i32 %26
}