#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*/ add_user_to_grp(int, int);
int fmyinput(char *, char *, int);
int /*<<< orphan*/ list_groups(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
void interactive_addusrgrp(int rid) {
  char inp[20];
  int grp, l;
  printf("\n == ADD USER TO A GROUP\n");
  list_groups(0);
  printf("\nPlease enter group number (for example 220), or 0 to go back\n");
  l = fmyinput("Group number? : ", inp, 16);
  sscanf(inp, "%x", &grp);
  if (!grp) {
    printf("Going back..\n");
    return;
  }
  printf("Adding user to group 0x%x (%d)\n", grp, grp);
  printf("Error messages if the user was already member of the group are "
         "harmless\n\n");
  add_user_to_grp(rid, grp);
  printf("\nFinished adding user to group\n\n");
}


x86 assembly (clang, -O0):
<interactive_addusrgrp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <list_groups@plt>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xed0(%rip),%rdi
mov    $0x10,%edx
call   1030 <fmyinput@plt>
mov    %eax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
lea    0xec9(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1070 <sscanf@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11c7 <interactive_addusrgrp+0x77>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1202 <interactive_addusrgrp+0xb2>
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1060 <add_user_to_grp@plt>
lea    0xeea(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interactive_addusrgrp>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <list_groups@plt>
lea    0xecb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe72(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x10,%edx
call   1040 <fmyinput@plt>
lea    0xe6a(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <sscanf@plt>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     11ec <interactive_addusrgrp+0x8c>
lea    0xe51(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%esi
mov    %ebp,%edi
call   1070 <add_user_to_grp@plt>
lea    0xef7(%rip),%rdi
jmp    11f3 <interactive_addusrgrp+0x93>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"\0A == ADD USER TO A GROUP\0A\00"
@.str.1 = [63 x i8] c"\0APlease enter group number (for example 220), or 0 to go back\0A\00"
@.str.2 = [17 x i8] c"Group number? : \00"
@.str.3 = [3 x i8] c"%x\00"
@.str.4 = [14 x i8] c"Going back..\0A\00"
@.str.5 = [32 x i8] c"Adding user to group 0x%x (%d)\0A\00"
@.str.6 = [74 x i8] c"Error messages if the user was already member of the group are harmless\0A\0A\00"
@.str.7 = [33 x i8] c"\0AFinished adding user to group\0A\0A\00"
define void @interactive_addusrgrp(i32 %0) {
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @list_groups(i32 0)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%10 = call i32 @fmyinput(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %9, i32 16)
store i32 %10, i32* %5
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %26
17: ; preds = %1
%18 = load i32, i32* %4
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.6, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = load i32, i32* %4
%24 = call i32 @add_user_to_grp(i32 %22, i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %26
26: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
@.str.2 = [17 x i8] c"Group number? : \00"
@.str.3 = [3 x i8] c"%x\00"
@.str.5 = [32 x i8] c"Adding user to group 0x%x (%d)\0A\00"
@str = [25 x i8] c"\0A == ADD USER TO A GROUP\00"
@str.8 = [62 x i8] c"\0APlease enter group number (for example 220), or 0 to go back\00"
@str.9 = [13 x i8] c"Going back..\00"
@str.10 = [73 x i8] c"Error messages if the user was already member of the group are harmless\0A\00"
@str.11 = [32 x i8] c"\0AFinished adding user to group\0A\00"
define void @interactive_addusrgrp(i32 %0) {
%2 = alloca [20 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @list_groups(i32 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.8, i64 0, i64 0))
%9 = call i32 @fmyinput(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %4, i32 16)
%10 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %11, i32 %11)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.10, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = call i32 @add_user_to_grp(i32 %0, i32 %16)
br label %18
18: ; preds = %1, %13
%19 = phi i8* [ getelementptr inbounds ([32 x i8], [32 x i8]* @str.11, i64 0, i64 0), %13 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0), %1 ]
%20 = call i32 @puts(i8* dereferenceable(1) %19)
ret void
}