#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 /*<<< orphan*/ uid_t;
typedef int /*<<< orphan*/ gid_t;

/* Variables and functions */
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
scalar_t__ malloc(int);
int /*<<< orphan*/ seteuid(int /*<<< orphan*/);
int /*<<< orphan*/ setregid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char *foo;
  foo = (char *)malloc(200);
  system("cat /etc/shadow");
  system(argv[1]);
  gid_t gid = getgid();
  uid_t uid = getuid();
  seteuid(uid);
  setregid(gid, gid);
  char cmdbuf[128] = "export IFS=' \t\n'; /usr/bin/file ";
  system(cmdbuf);
  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)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe62(%rip),%rdi
call   1040 <system@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <system@plt>
mov    $0x0,%al
call   1060 <getgid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1090 <seteuid@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1080 <setregid@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x80,%edx
call   1050 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%rbx
mov    $0xc8,%edi
call   1060 <malloc@plt>
lea    0xe84(%rip),%rdi
call   1040 <system@plt>
mov    0x8(%rbx),%rdi
call   1040 <system@plt>
xor    %eax,%eax
call   1050 <getgid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%edi
call   1080 <seteuid@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   1070 <setregid@plt>
movaps 0xecf(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xeb3(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe7b(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe5f(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe43(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe27(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe0b(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"cat /etc/shadow\00"
@__const.main.cmdbuf = [128 x i8] c"export IFS=' \09\0A'; /usr/bin/file \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @malloc(i32 200)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @system(i8* %15)
%17 = call i32 (...) @getgid()
store i32 %17, i32* %7
%18 = call i32 (...) @getuid()
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = call i32 @seteuid(i32 %19)
%21 = load i32, i32* %7
%22 = load i32, i32* %7
%23 = call i32 @setregid(i32 %21, i32 %22)
%24 = bitcast [128 x i8]* %9 to i8*
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = call i32 @system(i8* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"cat /etc/shadow\00"
@__const.main.cmdbuf = [128 x i8] c"export IFS=' \09\0A'; /usr/bin/file \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = tail call i64 @malloc(i32 200)
%5 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @system(i8* %7)
%9 = tail call i32 (...) @getgid()
%10 = tail call i32 (...) @getuid()
%11 = tail call i32 @seteuid(i32 %10)
%12 = tail call i32 @setregid(i32 %9, i32 %9)
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%14 = call i32 @system(i8* %13)
ret i32 0
}