#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*/ time_t;

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int geteuid();
int getuid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ setreuid(int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
scalar_t__ system(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int ruid, euid;
  char score[128];
  if (argc != 3) {
    printf("Usage: setuid_program name SSN\n");
    exit(1);
  }
  time_t current_time = time(NULL);
  ruid = getuid();
  euid = geteuid();
  if (setreuid(euid, euid)) {
    perror("setreuid");
  }
  char command[256];
  printf("Invalid user name or SSN.\n");
  sprintf(command,
          "echo \"%s: Invalid user name or SSN: %s,%s\"|cat >> error.log",
          ctime(&current_time), argv[1], argv[2]);
  if (system(command)) {
    perror("Logging");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d9 <main+0x39>
lea    0xe36(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %eax,-0xa4(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1070 <geteuid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1090 <setreuid@plt>
cmp    $0x0,%rax
je     121d <main+0x7d>
lea    0xe08(%rip),%rdi
call   10a0 <perror@plt>
lea    0xe05(%rip),%rdi
call   1060 <printf@plt>
lea    -0x1b0(%rbp),%rax
mov    %rax,-0x1b8(%rbp)
lea    -0xa4(%rbp),%rdi
call   1030 <ctime@plt>
mov    -0x1b8(%rbp),%rdi
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
lea    0xde0(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x1b0(%rbp),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
je     128b <main+0xeb>
lea    0xdfa(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x4(%rbp),%eax
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
cmp    $0x3,%edi
jne    1244 <main+0xa4>
mov    %rsi,%rbx
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1050 <getuid@plt>
xor    %eax,%eax
call   1070 <geteuid@plt>
mov    %eax,%edi
mov    %eax,%esi
call   1090 <setreuid@plt>
test   %rax,%rax
jne    1228 <main+0x88>
lea    0xe6b(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   1040 <ctime@plt>
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
lea    0xe09(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
test   %rax,%rax
jne    1236 <main+0x96>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret
lea    0xdd1(%rip),%rdi
call   10a0 <perror@plt>
jmp    11db <main+0x3b>
lea    0xe08(%rip),%rdi
call   10a0 <perror@plt>
jmp    121d <main+0x7d>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: setuid_program name SSN\0A\00"
@.str.1 = [9 x i8] c"setreuid\00"
@.str.2 = [27 x i8] c"Invalid user name or SSN.\0A\00"
@.str.3 = [60 x i8] c"echo \22%s: Invalid user name or SSN: %s,%s\22|cat >> error.log\00"
@.str.4 = [8 x i8] c"Logging\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca i32
%10 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 @time(i32* null)
store i32 %17, i32* %9
%18 = call i32 (...) @getuid()
store i32 %18, i32* %6
%19 = call i32 (...) @geteuid()
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* %7
%22 = call i64 @setreuid(i32 %20, i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24, %16
%27 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%29 = call i8* @ctime(i32* %9)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %32, i8* %35)
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%38 = call i64 @system(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %26
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %26
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [9 x i8] c"setreuid\00"
@.str.3 = [60 x i8] c"echo \22%s: Invalid user name or SSN: %s,%s\22|cat >> error.log\00"
@.str.4 = [8 x i8] c"Logging\00"
@str = [26 x i8] c"Invalid user name or SSN.\00"
@str.5 = [31 x i8] c"Usage: setuid_program name SSN\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = icmp eq i32 %0, 3
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = bitcast i32* %3 to i8*
%11 = tail call i32 @time(i32* null)
store i32 %11, i32* %3
%12 = tail call i32 (...) @getuid()
%13 = tail call i32 (...) @geteuid()
%14 = tail call i64 @setreuid(i32 %13, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%21 = call i8* @ctime(i32* %3)
%22 = getelementptr inbounds i8*, i8** %1, i64 1
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %23, i8* %25)
%27 = call i64 @system(i8* %19)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %18
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %18
ret i32 0
}