#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 *, char *, int, int);
int setuid(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
main(int argc, char *argv[]) {
  int cnt, rc, cc;
  char cmnd[1024];
  strcpy(cmnd, "/usr/sbin/dbmail-users");
  if (argc > 1) {
    for (cnt = 1; cnt < argc; cnt++) {
      strcat(cmnd, " ");
      strcat(cmnd, argv[cnt]);
    }
  } else {
    fprintf(stderr, "__ %s:  failed %d  %d\n", argv[0], rc, cc);
    return 255;
  }
  cc = setuid(0);
  rc = system(cmnd);
  if ((rc != 0) || (cc != 0)) {
    fprintf(stderr, "__ %s:  failed %d  %d\n", argv[0], rc, cc);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11d7 <main+0x87>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d2 <main+0x82>
lea    -0x420(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x3d>
jmp    1206 <main+0xb6>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe24(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1269 <main+0x119>
xor    %edi,%edi
call   1070 <setuid@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1233 <main+0xe3>
cmpl   $0x0,-0x1c(%rbp)
je     1262 <main+0x112>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xdc8(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1269 <main+0x119>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe95(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
cmp    $0x2,%ebp
jl     11ef <main+0x9f>
mov    %ebp,%r12d
mov    $0x1,%ebx
lea    0xe90(%rip),%r14
mov    %rsp,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
mov    (%r15,%rbx,8),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <main+0x40>
xor    %ebp,%ebp
xor    %edi,%edi
call   1070 <setuid@plt>
mov    %eax,%r14d
mov    %rsp,%rdi
call   1040 <system@plt>
mov    %eax,%ecx
or     %r14d,%ecx
je     120c <main+0xbc>
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%edi
mov    (%r15),%rdx
lea    0xe3b(%rip),%rsi
mov    %eax,%ecx
mov    %r14d,%r8d
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    120c <main+0xbc>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xff,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/usr/sbin/dbmail-users\00"
@.str.1 = [2 x i8] c" \00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"__ %s: failed %d %d\0A\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 i32
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %33
14: ; preds = %2
store i32 1, i32* %6
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strcat(i8* %22, i8* %27)
br label %29
29: ; preds = %19
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %15
32: ; preds = %15
br label %41
33: ; preds = %2
%34 = load i32, i32* @stderr
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 0
%37 = load i8*, i8** %36
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %38, i32 %39)
store i32 255, i32* %3
br label %59
41: ; preds = %32
%42 = call i32 @setuid(i32 0)
store i32 %42, i32* %8
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = call i32 @system(i8* %43)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
br i1 %46, label %50, label %47
47: ; preds = %41
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %47, %41
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = load i32, i32* %7
%56 = load i32, i32* %8
%57 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %54, i32 %55, i32 %56)
store i32 1, i32* %3
br label %59
58: ; preds = %47
store i32 0, i32* %3
br label %59
59: ; preds = %58, %50, %33
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [23 x i8] c"/usr/sbin/dbmail-users\00"
@.str.1 = [2 x i8] c" \00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"__ %s: failed %d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 1, %7 ], [ %15, %9 ]
%11 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
%13 = load i8*, i8** %12
%14 = call i32 @strcat(i8* %4, i8* %13)
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %8
br i1 %16, label %21, label %9
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %19, i32 undef, i32 undef)
br label %31
21: ; preds = %9
%22 = call i32 @setuid(i32 0)
%23 = call i32 @system(i8* %4)
%24 = icmp ne i32 %23, 0
%25 = icmp ne i32 %22, 0
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %1
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %23, i32 %22)
br label %31
31: ; preds = %21, %27, %17
%32 = phi i32 [ 1, %27 ], [ 255, %17 ], [ 0, %21 ]
ret i32 %32
}