#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 uid_t;
struct passwd {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct passwd *getpwuid(int);
int rand_interval(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ system(char *);
int create_user() {
  struct passwd *p;
  uid_t uid = rand_interval(1001, 50000);
  while ((p = getpwuid(uid)) != NULL)
    uid = rand_interval(1001, 50000);
  char add[50];
  sprintf(add, "useradd -M -u %d u%d -p 123 ", uid, uid);
  fprintf(stderr, add);
  fprintf(stderr, "\n");
  system(add);
  return uid;
}


x86 assembly (clang, -O0):
<create_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x3e9,%edi
mov    $0xc350,%esi
call   1070 <rand_interval@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <getpwuid@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1197 <create_user+0x47>
mov    $0x3e9,%edi
mov    $0xc350,%esi
call   1070 <rand_interval@plt>
mov    %eax,-0xc(%rbp)
jmp    116a <create_user+0x1a>
lea    -0x40(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe58(%rip),%rsi
call   1060 <sprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
call   1050 <fprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x40(%rbp),%rdi
call   1040 <system@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_user>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
nopl   0x0(%rax)
mov    $0x3e9,%edi
mov    $0xc350,%esi
call   1070 <rand_interval@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <getpwuid@plt>
test   %rax,%rax
jne    1160 <create_user+0x10>
lea    0xe7c(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
mov    %ebx,%ecx
call   1060 <sprintf@plt>
mov    0x2e46(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xe6e(%rip),%rsi
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1040 <system@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.passwd = type { i32 }
@.str = [29 x i8] c"useradd -M -u %d u%d -p 123 \00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @create_user() {
%1 = alloca %struct.passwd*
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = call i32 @rand_interval(i32 1001, i32 50000)
store i32 %4, i32* %2
br label %5
5: ; preds = %9, %0
%6 = load i32, i32* %2
%7 = call %struct.passwd* @getpwuid(i32 %6)
store %struct.passwd* %7, %struct.passwd** %1
%8 = icmp ne %struct.passwd* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @rand_interval(i32 1001, i32 50000)
store i32 %10, i32* %2
br label %5
11: ; preds = %5
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
%16 = load i32, i32* @stderr
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%18 = call i32 @fprintf(i32 %16, i8* %17)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%22 = call i32 @system(i8* %21)
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.passwd = type { i32 }
@.str = [29 x i8] c"useradd -M -u %d u%d -p 123 \00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @create_user() {
%1 = alloca [50 x i8]
%2 = tail call i32 @rand_interval(i32 1001, i32 50000)
%3 = tail call %struct.passwd* @getpwuid(i32 %2)
%4 = icmp eq %struct.passwd* %3, null
br i1 %4, label %9, label %5
5: ; preds = %0, %5
%6 = tail call i32 @rand_interval(i32 1001, i32 50000)
%7 = tail call %struct.passwd* @getpwuid(i32 %6)
%8 = icmp eq %struct.passwd* %7, null
br i1 %8, label %9, label %5
9: ; preds = %5, %0
%10 = phi i32 [ %2, %0 ], [ %6, %5 ]
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %10)
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* %11)
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @system(i8* %11)
ret i32 %10
}