#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 EXIT_SUCCESS;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  printf("= Aufgabe 10.1 =\n");
  printf("Inhalt der Variable argv[0] ist %s\n", argv[0]);
  printf("= Aufgabe 10.2 =\n");
  char name[21] = "";
  if (argc > 1) {
    strcpy(name, argv[1]);
  } else {
    printf("Geben Sie ihren Namen ein: \n");
    fflush(stdout);
    scanf("%s", name);
    fflush(stdin);
  }
  printf("Hallo, %s!\n", name);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x15,%edx
call   1050 <memset@plt>
cmpl   $0x1,-0x8(%rbp)
jle    11c7 <main+0x77>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    1201 <main+0xb1>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x30(%rbp),%rsi
lea    0xe77(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x30(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xed1(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%rsi
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
call   1040 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0xd(%rsp)
cmp    $0x2,%ebp
jl     11a7 <main+0x57>
mov    0x8(%rbx),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
jmp    11de <main+0x8e>
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe5c(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe42(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"= Aufgabe 10.1 =\0A\00"
@.str.1 = [36 x i8] c"Inhalt der Variable argv[0] ist %s\0A\00"
@.str.2 = [18 x i8] c"= Aufgabe 10.2 =\0A\00"
@.str.3 = [29 x i8] c"Geben Sie ihren Namen ein: \0A\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.5 = [12 x i8] c"Hallo, %s!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [21 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 0
%10 = load i8*, i8** %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%13 = bitcast [21 x i8]* %6 to i8*
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %17, i8* %20)
br label %30
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
%26 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @stdin
%29 = call i32 @fflush(i32 %28)
br label %30
30: ; preds = %22, %16
%31 = getelementptr inbounds [21 x i8], [21 x i8]* %6, i64 0, i64 0
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}

LLVM IR (-O2):
@.str.1 = [36 x i8] c"Inhalt der Variable argv[0] ist %s\0A\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@stdin = global i32 0
@.str.5 = [12 x i8] c"Hallo, %s!\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [17 x i8] c"= Aufgabe 10.1 =\00"
@str.6 = [17 x i8] c"= Aufgabe 10.2 =\00"
@str.7 = [28 x i8] c"Geben Sie ihren Namen ein: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [21 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %3, i64 0, i64 0
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %8, i8* %12)
br label %21
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.7, i64 0, i64 0))
%16 = load i32, i32* @stdout
%17 = tail call i32 @fflush(i32 %16)
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%19 = load i32, i32* @stdin
%20 = call i32 @fflush(i32 %19)
br label %21
21: ; preds = %14, %10
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}