#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*/ err(int, char *);
int /*<<< orphan*/ free(char *);
char *read_str(int);
int /*<<< orphan*/ send_pid(int);
int /*<<< orphan*/ send_str(int, char *);
int /*<<< orphan*/ send_ull(int, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
void overflow(char *filename, char *outname) {
  send_pid(30);
  send_ull(30, 0);
  send_str(30, filename);
  send_str(30, outname);
  char *resp = read_str(30);
  if (strcmp(resp, "OK") != 0) {
    err(1, "resp not OK");
  }
  free(resp);
}


x86 assembly (clang, -O0):
<overflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1050 <send_ull@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1e,%edi
call   1070 <send_str@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1e,%edi
call   1070 <send_str@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11eb <overflow+0x7b>
mov    $0x1,%edi
lea    0xe1a(%rip),%rsi
call   1080 <err@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<overflow>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x1e,%edi
call   1040 <send_pid@plt>
mov    $0x1e,%edi
xor    %esi,%esi
call   1050 <send_ull@plt>
mov    $0x1e,%edi
mov    %rbx,%rsi
call   1070 <send_str@plt>
mov    $0x1e,%edi
mov    %r14,%rsi
call   1070 <send_str@plt>
mov    $0x1e,%edi
call   1090 <read_str@plt>
mov    %rax,%rbx
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11dc <overflow+0x6c>
lea    0xe2e(%rip),%rsi
mov    $0x1,%edi
call   1080 <err@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"resp not OK\00"
define void @overflow(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i32 @send_pid(i32 30)
%7 = call i32 @send_ull(i32 30, i32 0)
%8 = load i8*, i8** %3
%9 = call i32 @send_str(i32 30, i8* %8)
%10 = load i8*, i8** %4
%11 = call i32 @send_str(i32 30, i8* %10)
%12 = call i8* @read_str(i32 30)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = load i8*, i8** %5
%20 = call i32 @free(i8* %19)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"OK\00"
@.str.1 = [12 x i8] c"resp not OK\00"
define void @overflow(i8* %0, i8* %1) {
%3 = tail call i32 @send_pid(i32 30)
%4 = tail call i32 @send_ull(i32 30, i32 0)
%5 = tail call i32 @send_str(i32 30, i8* %0)
%6 = tail call i32 @send_str(i32 30, i8* %1)
%7 = tail call i8* @read_str(i32 30)
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = tail call i32 @free(i8* %7)
ret void
}