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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ getuid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  FILE *outFilePtr;
  if (argc != 2) {
    usage(argv[0]);
    return (2);
  }
  if (0 != getuid()) {
    printf("Root permissions required for this operation.\n");
    return (1);
  }
  outFilePtr = fopen("/etc/machine-info", "w");
  fprintf(outFilePtr, "PRETTY_HOSTNAME=%s\n", argv[1]);
  fclose(outFilePtr);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
movl   $0x2,-0x4(%rbp)
jmp    1209 <main+0xa9>
mov    $0x0,%al
call   1040 <getuid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c5 <main+0x65>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1209 <main+0xa9>
lea    0xe63(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    118b <main+0x2b>
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
je     119a <main+0x3a>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    11d4 <main+0x74>
mov    (%rbx),%rdi
call   1070 <usage@plt>
mov    $0x2,%eax
jmp    11d4 <main+0x74>
lea    0xe5f(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    0x8(%rbx),%rdx
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Root permissions required for this operation.\0A\00"
@.str.1 = [18 x i8] c"/etc/machine-info\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [20 x i8] c"PRETTY_HOSTNAME=%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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @usage(i8* %12)
store i32 2, i32* %3
br label %29
14: ; preds = %2
%15 = call i64 (...) @getuid()
%16 = icmp ne i64 0, %15
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %29
19: ; preds = %14
%20 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %6
%27 = call i32 @fclose(i32* %26)
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %3
br label %29
29: ; preds = %19, %17, %9
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"/etc/machine-info\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [20 x i8] c"PRETTY_HOSTNAME=%s\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [46 x i8] c"Root permissions required for this operation.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %19
7: ; preds = %2
%8 = tail call i64 (...) @getuid()
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %19
12: ; preds = %7
%13 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = tail call i32 @fclose(i32* %13)
%18 = load i32, i32* @EXIT_SUCCESS
br label %19
19: ; preds = %12, %10, %4
%20 = phi i32 [ 2, %4 ], [ 1, %10 ], [ %18, %12 ]
ret i32 %20
}