#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ lua_pushstring(char *);
int /*<<< orphan*/ lua_setglobal(char *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void assign(char *arg) {
  if (strlen(arg) >= 500)
    fprintf(stderr, "lua: shell argument too long");
  else {
    char buffer[500];
    char *eq = strchr(arg, '=');
    lua_pushstring(eq + 1);
    strncpy(buffer, arg, eq - arg);
    buffer[eq - arg] = 0;
    lua_setglobal(buffer);
  }
}


x86 assembly (clang, -O0):
<assign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1f4,%eax
jl     119d <assign+0x3d>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1204 <assign+0xa4>
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x208(%rbp)
mov    -0x208(%rbp),%rdi
add    $0x1,%rdi
call   1080 <lua_pushstring@plt>
lea    -0x200(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x208(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x208(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x200(%rbp,%rax,1)
lea    -0x200(%rbp),%rdi
call   1060 <lua_setglobal@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assign>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x1f4,%eax
jl     119c <assign+0x3c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <fprintf@plt>
mov    %r14,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1080 <lua_pushstring@plt>
sub    %r14,%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
call   1060 <lua_setglobal@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"lua: shell argument too long\00"
define void @assign(i8* %0) {
%2 = alloca i8*
%3 = alloca [500 x i8]
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = icmp sge i32 %6, 500
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %34
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i8* @strchr(i8* %12, i8 signext 61)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = call i32 @lua_pushstring(i8* %15)
%17 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%18 = load i8*, i8** %2
%19 = load i8*, i8** %4
%20 = load i8*, i8** %2
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = trunc i64 %23 to i32
%25 = call i32 @strncpy(i8* %17, i8* %18, i32 %24)
%26 = load i8*, i8** %4
%27 = load i8*, i8** %2
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%33 = call i32 @lua_setglobal(i8* %32)
br label %34
34: ; preds = %11, %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"lua: shell argument too long\00"
define void @assign(i8* %0) {
%2 = alloca [500 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 499
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%10 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = tail call i32 @lua_pushstring(i8* %11)
%13 = ptrtoint i8* %10 to i64
%14 = ptrtoint i8* %0 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @strncpy(i8* %9, i8* %0, i32 %16)
%18 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 %15
store i8 0, i8* %18
%19 = call i32 @lua_setglobal(i8* %9)
br label %20
20: ; preds = %8, %5
ret void
}