#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 */
struct rlimit {
  int rlim_max;
};
struct passwd {
  char *pw_dir;
  int /*<<< orphan*/ pw_uid;
  int /*<<< orphan*/ pw_gid;
};

/* Variables and functions */
int /*<<< orphan*/ RLIMIT_NOFILE;
int RLIM_INFINITY;
int S_IWGRP;
int S_IWOTH;
int asprintf(char **, char *, char *);
int chdir(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int geteuid();
struct passwd *getpwuid(int);
int getrlimit(int /*<<< orphan*/, struct rlimit *);
int /*<<< orphan*/ perror(char *);
int setgroups(int /*<<< orphan*/, int /*<<< orphan*/ *);
int setregid(int /*<<< orphan*/, int /*<<< orphan*/);
int setreuid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ umask(int);
int main(int argc, char *argv[], char *envp[]) {
  char *apt_argv[] = {"/usr/bin/apt-get", "-q", "update", NULL};
  char *apt_envp[] = {"PATH=/bin:/usr/bin", NULL, NULL, NULL, NULL};
  struct passwd *pwd = getpwuid(geteuid());
  if (!pwd) {
    fprintf(stderr, "error: Unable to find passwd entry for uid %d (%s)\n",
            geteuid(), strerror(errno));
    exit(1);
  }
  if (asprintf(&apt_envp[1], "HOME=%s", pwd->pw_dir) == -1) {
    perror("error: Unable to create HOME environment variable");
    exit(1);
  }
  int proxy_arg = 2;
  char *http_proxy = getenv("http_proxy");
  if (http_proxy) {
    if (asprintf(&apt_envp[proxy_arg], "http_proxy=%s", http_proxy) == -1) {
      perror("error: Unable to set http_proxy environment variable");
      exit(1);
    }
    proxy_arg++;
  }
  char *https_proxy = getenv("https_proxy");
  if (https_proxy) {
    if (asprintf(&apt_envp[proxy_arg], "https_proxy=%s", https_proxy) == -1) {
      perror("error: Unable to set https_proxy environment variable");
      exit(1);
    }
  }
  if (setgroups(0, NULL) == -1) {
    perror("error: Unable to set supplementary groups IDs");
    exit(1);
  }
  if (setregid(pwd->pw_gid, pwd->pw_gid) == -1) {
    fprintf(stderr, "error: Unable to set real and effective gid (%s)\n",
            strerror(errno));
    exit(1);
  }
  if (setreuid(pwd->pw_uid, pwd->pw_uid) == -1) {
    perror("error: Unable to set real and effective uid");
    exit(1);
  }
  struct rlimit rlp;
  if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) {
    perror("error: Unable to determine file descriptor limits");
    exit(1);
  }
  int file_max;
  if (rlp.rlim_max == RLIM_INFINITY || rlp.rlim_max > 4096)
    file_max = 4096;
  else
    file_max = rlp.rlim_max;
  int file;
  for (file = 3; file < file_max; file++) {
    close(file);
  }
  umask(S_IWGRP | S_IWOTH);
  if (chdir("/") == -1) {
    perror("error: Unable to change working directory");
    exit(1);
  }
  execve(apt_argv[0], apt_argv, apt_envp);
  perror("error: Unable to execute apt-get");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2b9c(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2b99(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2b96(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2b93(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
lea    0xdab(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    12e2 <main+0xd2>
mov    0x2d38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa8(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,-0xa4(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0xa8(%rbp),%edi
mov    -0xa4(%rbp),%edx
mov    %rax,%rcx
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
lea    -0x70(%rbp),%rdi
add    $0x8,%rdi
mov    -0x78(%rbp),%rax
mov    (%rax),%rdx
lea    0xd6a(%rip),%rsi
call   10f0 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    131c <main+0x10c>
lea    0xd5d(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x2,-0x7c(%rbp)
lea    0xd72(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     138e <main+0x17e>
movslq -0x7c(%rbp),%rax
lea    -0x70(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x88(%rbp),%rdx
lea    0xd46(%rip),%rsi
call   10f0 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    1385 <main+0x175>
lea    0xd3f(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
lea    0xd55(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
je     13f5 <main+0x1e5>
movslq -0x7c(%rbp),%rax
lea    -0x70(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x90(%rbp),%rdx
lea    0xd2a(%rip),%rsi
call   10f0 <asprintf@plt>
cmp    $0xffffffff,%eax
jne    13f0 <main+0x1e0>
lea    0xd24(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
jmp    13f5 <main+0x1e5>
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1090 <setgroups@plt>
cmp    $0xffffffff,%eax
jne    141f <main+0x20f>
lea    0xd2b(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x78(%rbp),%rax
mov    0xc(%rax),%edi
mov    -0x78(%rbp),%rax
mov    0xc(%rax),%esi
call   10e0 <setregid@plt>
cmp    $0xffffffff,%eax
jne    1479 <main+0x269>
mov    0x2b8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xac(%rbp)
mov    0x2b77(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0xac(%rbp),%edi
mov    %rax,%rdx
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x78(%rbp),%rax
mov    0x8(%rax),%esi
call   10d0 <setreuid@plt>
cmp    $0xffffffff,%eax
jne    14ab <main+0x29b>
lea    0xcff(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
lea    -0x98(%rbp),%rsi
call   1120 <getrlimit@plt>
cmp    $0xffffffff,%eax
jne    14df <main+0x2cf>
lea    0xcf7(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x98(%rbp),%eax
mov    0x2ad4(%rip),%rcx
cmp    (%rcx),%eax
je     1504 <main+0x2f4>
cmpl   $0x1000,-0x98(%rbp)
jle    1513 <main+0x303>
movl   $0x1000,-0x9c(%rbp)
jmp    151f <main+0x30f>
mov    -0x98(%rbp),%eax
mov    %eax,-0x9c(%rbp)
movl   $0x3,-0xa0(%rbp)
mov    -0xa0(%rbp),%eax
cmp    -0x9c(%rbp),%eax
jge    155a <main+0x34a>
mov    -0xa0(%rbp),%edi
call   1080 <close@plt>
mov    -0xa0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa0(%rbp)
jmp    1529 <main+0x319>
mov    0x2a87(%rip),%rax
mov    (%rax),%edi
mov    0x2a46(%rip),%rax
or     (%rax),%edi
call   10c0 <umask@plt>
lea    0xc81(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
jne    159c <main+0x38c>
lea    0xc6e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x40(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   10a0 <execve@plt>
lea    0xc71(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
movaps 0x2bd3(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2bb7(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xde0(%rip),%rax
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%edi
call   1040 <getpwuid@plt>
test   %rax,%rax
je     13c8 <main+0x1c8>
mov    %rax,%rbx
lea    0x18(%rsp),%rdi
mov    (%rax),%rdx
lea    0xdf9(%rip),%rsi
call   10e0 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1407 <main+0x207>
lea    0xe1e(%rip),%rdi
call   1030 <getenv@plt>
mov    $0x2,%ebp
test   %rax,%rax
je     12af <main+0xaf>
lea    0x20(%rsp),%rdi
lea    0xe0e(%rip),%rsi
mov    %rax,%rdx
call   10e0 <asprintf@plt>
mov    $0x3,%ebp
cmp    $0xffffffff,%eax
je     1468 <main+0x268>
lea    0xe34(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12e0 <main+0xe0>
lea    (%rsp,%rbp,8),%rdi
add    $0x10,%rdi
lea    0xe27(%rip),%rsi
mov    %rax,%rdx
call   10e0 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1471 <main+0x271>
xor    %edi,%edi
xor    %esi,%esi
call   1080 <setgroups@plt>
cmp    $0xffffffff,%eax
je     1410 <main+0x210>
mov    0xc(%rbx),%edi
mov    %edi,%esi
call   10d0 <setregid@plt>
cmp    $0xffffffff,%eax
je     1419 <main+0x219>
mov    0x8(%rbx),%edi
mov    %edi,%esi
call   10c0 <setreuid@plt>
cmp    $0xffffffff,%eax
je     144d <main+0x24d>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1110 <getrlimit@plt>
cmp    $0xffffffff,%eax
je     1456 <main+0x256>
mov    0x8(%rsp),%eax
mov    0x2c81(%rip),%rcx
cmp    (%rcx),%eax
mov    $0x1000,%ecx
mov    %eax,%ebp
cmove  %ecx,%ebp
cmp    $0x1001,%eax
cmovge %ecx,%ebp
cmp    $0x4,%ebp
jl     136e <main+0x16e>
mov    $0x3,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1070 <close@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1360 <main+0x160>
mov    0x2c73(%rip),%rax
mov    0x2c34(%rip),%rcx
mov    (%rcx),%edi
or     (%rax),%edi
call   10b0 <umask@plt>
lea    0xe6d(%rip),%rdi
call   1050 <chdir@plt>
cmp    $0xffffffff,%eax
je     145f <main+0x25f>
lea    0xc5f(%rip),%rdi
lea    0x40(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1090 <execve@plt>
lea    0xe6e(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2c01(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1060 <geteuid@plt>
mov    %eax,%ebp
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xc3f(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc5c(%rip),%rdi
jmp    1478 <main+0x278>
lea    0xd24(%rip),%rdi
jmp    1478 <main+0x278>
mov    0x2bb0(%rip),%rax
mov    (%rax),%ebx
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xd32(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xd47(%rip),%rdi
jmp    1478 <main+0x278>
lea    0xd6a(%rip),%rdi
jmp    1478 <main+0x278>
lea    0xd95(%rip),%rdi
jmp    1478 <main+0x278>
lea    0xc46(%rip),%rdi
jmp    1478 <main+0x278>
lea    0xc8d(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.passwd = type { i8*, i32, i32 }
%struct.rlimit = type { i32 }
@.str = [17 x i8] c"/usr/bin/apt-get\00"
@.str.1 = [3 x i8] c"-q\00"
@.str.2 = [7 x i8] c"update\00"
@__const.main.apt_argv = [4 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [19 x i8] c"PATH=/bin:/usr/bin\00"
@stderr = global i32 0
@.str.4 = [52 x i8] c"error: Unable to find passwd entry for uid %d (%s)\0A\00"
@errno = global i32 0
@.str.5 = [8 x i8] c"HOME=%s\00"
@.str.6 = [50 x i8] c"error: Unable to create HOME environment variable\00"
@.str.7 = [11 x i8] c"http_proxy\00"
@.str.8 = [14 x i8] c"http_proxy=%s\00"
@.str.9 = [53 x i8] c"error: Unable to set http_proxy environment variable\00"
@.str.10 = [12 x i8] c"https_proxy\00"
@.str.11 = [15 x i8] c"https_proxy=%s\00"
@.str.12 = [54 x i8] c"error: Unable to set https_proxy environment variable\00"
@.str.13 = [46 x i8] c"error: Unable to set supplementary groups IDs\00"
@.str.14 = [50 x i8] c"error: Unable to set real and effective gid (%s)\0A\00"
@.str.15 = [44 x i8] c"error: Unable to set real and effective uid\00"
@RLIMIT_NOFILE = global i32 0
@.str.16 = [50 x i8] c"error: Unable to determine file descriptor limits\00"
@RLIM_INFINITY = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.17 = [2 x i8] c"/\00"
@.str.18 = [42 x i8] c"error: Unable to change working directory\00"
@.str.19 = [33 x i8] c"error: Unable to execute apt-get\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [4 x i8*]
%9 = alloca [5 x i8*]
%10 = alloca %struct.passwd*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca %struct.rlimit
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%17 = bitcast [4 x i8*]* %8 to i8*
%18 = bitcast [5 x i8*]* %9 to i8*
%19 = bitcast i8* %18 to [5 x i8*]*
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %19, i32 0, i32 0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i32 0, i32 0), i8** %20
%21 = call i32 (...) @geteuid()
%22 = call %struct.passwd* @getpwuid(i32 %21)
store %struct.passwd* %22, %struct.passwd** %10
%23 = load %struct.passwd*, %struct.passwd** %10
%24 = icmp ne %struct.passwd* %23, null
br i1 %24, label %32, label %25
25: ; preds = %3
%26 = load i32, i32* @stderr
%27 = call i32 (...) @geteuid()
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %27, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %3
%33 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i64 0, i64 1
%34 = load %struct.passwd*, %struct.passwd** %10
%35 = getelementptr inbounds %struct.passwd, %struct.passwd* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @asprintf(i8** %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32
store i32 2, i32* %11
%43 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i8* %43, i8** %12
%44 = load i8*, i8** %12
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %59
46: ; preds = %42
%47 = load i32, i32* %11
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i64 0, i64 %48
%50 = load i8*, i8** %12
%51 = call i32 @asprintf(i8** %49, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %46
%54 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %46
%57 = load i32, i32* %11
%58 = add nsw i32 %57, 1
store i32 %58, i32* %11
br label %59
59: ; preds = %56, %42
%60 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
store i8* %60, i8** %13
%61 = load i8*, i8** %13
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %74
63: ; preds = %59
%64 = load i32, i32* %11
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i64 0, i64 %65
%67 = load i8*, i8** %13
%68 = call i32 @asprintf(i8** %66, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %73
70: ; preds = %63
%71 = call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.12, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %63
br label %74
74: ; preds = %73, %59
%75 = call i32 @setgroups(i32 0, i32* null)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
%79 = call i32 @exit(i32 1)
unreachable
80: ; preds = %74
%81 = load %struct.passwd*, %struct.passwd** %10
%82 = getelementptr inbounds %struct.passwd, %struct.passwd* %81, i32 0, i32 2
%83 = load i32, i32* %82
%84 = load %struct.passwd*, %struct.passwd** %10
%85 = getelementptr inbounds %struct.passwd, %struct.passwd* %84, i32 0, i32 2
%86 = load i32, i32* %85
%87 = call i32 @setregid(i32 %83, i32 %86)
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %95
89: ; preds = %80
%90 = load i32, i32* @stderr
%91 = load i32, i32* @errno
%92 = call i8* @strerror(i32 %91)
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %90, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.14, i64 0, i64 0), i8* %92)
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %80
%96 = load %struct.passwd*, %struct.passwd** %10
%97 = getelementptr inbounds %struct.passwd, %struct.passwd* %96, i32 0, i32 1
%98 = load i32, i32* %97
%99 = load %struct.passwd*, %struct.passwd** %10
%100 = getelementptr inbounds %struct.passwd, %struct.passwd* %99, i32 0, i32 1
%101 = load i32, i32* %100
%102 = call i32 @setreuid(i32 %98, i32 %101)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %95
%105 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %95
%108 = load i32, i32* @RLIMIT_NOFILE
%109 = call i32 @getrlimit(i32 %108, %struct.rlimit* %14)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %114
111: ; preds = %107
%112 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %107
%115 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %14, i32 0, i32 0
%116 = load i32, i32* %115
%117 = load i32, i32* @RLIM_INFINITY
%118 = icmp eq i32 %116, %117
br i1 %118, label %123, label %119
119: ; preds = %114
%120 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %14, i32 0, i32 0
%121 = load i32, i32* %120
%122 = icmp sgt i32 %121, 4096
br i1 %122, label %123, label %124
123: ; preds = %119, %114
store i32 4096, i32* %15
br label %127
124: ; preds = %119
%125 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %14, i32 0, i32 0
%126 = load i32, i32* %125
store i32 %126, i32* %15
br label %127
127: ; preds = %124, %123
store i32 3, i32* %16
br label %128
128: ; preds = %135, %127
%129 = load i32, i32* %16
%130 = load i32, i32* %15
%131 = icmp slt i32 %129, %130
br i1 %131, label %132, label %138
132: ; preds = %128
%133 = load i32, i32* %16
%134 = call i32 @close(i32 %133)
br label %135
135: ; preds = %132
%136 = load i32, i32* %16
%137 = add nsw i32 %136, 1
store i32 %137, i32* %16
br label %128
138: ; preds = %128
%139 = load i32, i32* @S_IWGRP
%140 = load i32, i32* @S_IWOTH
%141 = or i32 %139, %140
%142 = call i32 @umask(i32 %141)
%143 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%144 = icmp eq i32 %143, -1
br i1 %144, label %145, label %148
145: ; preds = %138
%146 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.18, i64 0, i64 0))
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %138
%149 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%150 = load i8*, i8** %149
%151 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%152 = getelementptr inbounds [5 x i8*], [5 x i8*]* %9, i64 0, i64 0
%153 = call i32 @execve(i8* %150, i8** %151, i8** %152)
%154 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.19, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
%struct.rlimit = type { i32 }
%struct.passwd = type { i8*, i32, i32 }
@.str = [17 x i8] c"/usr/bin/apt-get\00"
@.str.1 = [3 x i8] c"-q\00"
@.str.2 = [7 x i8] c"update\00"
@__const.main.apt_argv = [4 x i8*] [i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [19 x i8] c"PATH=/bin:/usr/bin\00"
@stderr = global i32 0
@.str.4 = [52 x i8] c"error: Unable to find passwd entry for uid %d (%s)\0A\00"
@errno = global i32 0
@.str.5 = [8 x i8] c"HOME=%s\00"
@.str.6 = [50 x i8] c"error: Unable to create HOME environment variable\00"
@.str.7 = [11 x i8] c"http_proxy\00"
@.str.8 = [14 x i8] c"http_proxy=%s\00"
@.str.9 = [53 x i8] c"error: Unable to set http_proxy environment variable\00"
@.str.10 = [12 x i8] c"https_proxy\00"
@.str.11 = [15 x i8] c"https_proxy=%s\00"
@.str.12 = [54 x i8] c"error: Unable to set https_proxy environment variable\00"
@.str.13 = [46 x i8] c"error: Unable to set supplementary groups IDs\00"
@.str.14 = [50 x i8] c"error: Unable to set real and effective gid (%s)\0A\00"
@.str.15 = [44 x i8] c"error: Unable to set real and effective uid\00"
@RLIMIT_NOFILE = global i32 0
@.str.16 = [50 x i8] c"error: Unable to determine file descriptor limits\00"
@RLIM_INFINITY = global i32 0
@S_IWGRP = global i32 0
@S_IWOTH = global i32 0
@.str.17 = [2 x i8] c"/\00"
@.str.18 = [42 x i8] c"error: Unable to change working directory\00"
@.str.19 = [33 x i8] c"error: Unable to execute apt-get\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [4 x i8*]
%5 = alloca [5 x i8*]
%6 = alloca %struct.rlimit
%7 = bitcast [4 x i8*]* %4 to i8*
%8 = bitcast [5 x i8*]* %5 to i8*
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %9
%10 = tail call i32 (...) @geteuid()
%11 = tail call %struct.passwd* @getpwuid(i32 %10)
%12 = icmp eq %struct.passwd* %11, null
br i1 %12, label %13, label %20
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = tail call i32 (...) @geteuid()
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %15, i8* %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 1
%22 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i32 @asprintf(i8** %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %20
%30 = call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i8* %30, null
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 2
%34 = call i32 @asprintf(i8** %33, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %30)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @perror(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32, %29
%40 = phi i64 [ 2, %29 ], [ 3, %32 ]
%41 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0))
%42 = icmp eq i8* %41, null
br i1 %42, label %50, label %43
43: ; preds = %39
%44 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 %40
%45 = call i32 @asprintf(i8** %44, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %41)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.12, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43, %39
%51 = call i32 @setgroups(i32 0, i32* null)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.13, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %50
%57 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 2
%58 = load i32, i32* %57
%59 = call i32 @setregid(i32 %58, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = load i32, i32* @errno
%64 = call i8* @strerror(i32 %63)
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.14, i64 0, i64 0), i8* %64)
%66 = call i32 @exit(i32 1)
unreachable
67: ; preds = %56
%68 = getelementptr inbounds %struct.passwd, %struct.passwd* %11, i64 0, i32 1
%69 = load i32, i32* %68
%70 = call i32 @setreuid(i32 %69, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.15, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %67
%76 = bitcast %struct.rlimit* %6 to i8*
%77 = load i32, i32* @RLIMIT_NOFILE
%78 = call i32 @getrlimit(i32 %77, %struct.rlimit* %6)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %83
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %75
%84 = getelementptr inbounds %struct.rlimit, %struct.rlimit* %6, i64 0, i32 0
%85 = load i32, i32* %84
%86 = load i32, i32* @RLIM_INFINITY
%87 = icmp eq i32 %85, %86
%88 = icmp sgt i32 %85, 4096
%89 = or i1 %88, %87
%90 = select i1 %89, i32 4096, i32 %85
%91 = icmp sgt i32 %90, 3
br i1 %91, label %92, label %97
92: ; preds = %83, %92
%93 = phi i32 [ %95, %92 ], [ 3, %83 ]
%94 = call i32 @close(i32 %93)
%95 = add nuw nsw i32 %93, 1
%96 = icmp eq i32 %95, %90
br i1 %96, label %97, label %92
97: ; preds = %92, %83
%98 = load i32, i32* @S_IWGRP
%99 = load i32, i32* @S_IWOTH
%100 = or i32 %99, %98
%101 = call i32 @umask(i32 %100)
%102 = call i32 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.17, i64 0, i64 0))
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %107
104: ; preds = %97
%105 = call i32 @perror(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.18, i64 0, i64 0))
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %97
%108 = getelementptr inbounds [4 x i8*], [4 x i8*]* %4, i64 0, i64 0
%109 = call i32 @execve(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %108, i8** %9)
%110 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.19, i64 0, i64 0))
ret i32 1
}