#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 */
struct utsname {
  int /*<<< orphan*/ machine;
};

/* Variables and functions */
int execv(char *, char **);
int execvp(char *, char **);
int /*<<< orphan*/ exit(int);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcat(char *, char const *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strstr(int /*<<< orphan*/, char *);
int uname(struct utsname *);
int main(int argc, char *argv[]) {
  struct utsname sys_uname;
  char *newprog;
  const char *suffix = 0;
  if (-1 == uname(&sys_uname)) {
    perror("uname");
    exit(255);
  }
  newprog = malloc(strlen(argv[0]) + 3);
  strcpy(newprog, argv[0]);
  suffix = "32";
  if ((char *)0 != strstr(sys_uname.machine, "64"))
    suffix = "64";
  strcat(newprog, suffix);
  if ((char *)0 == strchr(newprog, '/')) {
    return execvp(newprog, argv);
  } else {
    return execv(newprog, argv);
  }
}


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)
movq   $0x0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <uname@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11fc <main+0x4c>
lea    0xe13(%rip),%rdi
call   1080 <perror@plt>
mov    $0xff,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x3,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
lea    0xdd7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    0xdcc(%rip),%rsi
call   10d0 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     125b <main+0xab>
lea    0xdb2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1299 <main+0xe9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <execvp@plt>
mov    %eax,-0x4(%rbp)
jmp    12a9 <main+0xf9>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10c0 <execv@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0x8(%rsp),%rdi
call   1060 <uname@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0x96>
mov    (%r14),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    0x3(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    0x8(%rsp),%edi
lea    0xe11(%rip),%r15
mov    %r15,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
lea    0xdfc(%rip),%rsi
cmovne %r15,%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
test   %rax,%rax
je     123c <main+0x8c>
pop    %rbx
pop    %r14
pop    %r15
jmp    10c0 <execv@plt>
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <execvp@plt>
lea    0xdb3(%rip),%rdi
call   1080 <perror@plt>
mov    $0xff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [6 x i8] c"uname\00"
@.str.1 = [3 x i8] c"32\00"
@.str.2 = [3 x i8] c"64\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.utsname
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
%9 = call i32 @uname(%struct.utsname* %6)
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 255)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 3
%20 = call i8* @malloc(i64 %19)
store i8* %20, i8** %7
%21 = load i8*, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
%26 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i8* @strstr(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i8* null, %28
br i1 %29, label %30, label %31
30: ; preds = %14
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %31
31: ; preds = %30, %14
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = call i32 @strcat(i8* %32, i8* %33)
%35 = load i8*, i8** %7
%36 = call i8* @strchr(i8* %35, i8 signext 47)
%37 = icmp eq i8* null, %36
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i8*, i8** %7
%40 = load i8**, i8*** %5
%41 = call i32 @execvp(i8* %39, i8** %40)
store i32 %41, i32* %3
br label %46
42: ; preds = %31
%43 = load i8*, i8** %7
%44 = load i8**, i8*** %5
%45 = call i32 @execv(i8* %43, i8** %44)
store i32 %45, i32* %3
br label %46
46: ; preds = %42, %38
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [6 x i8] c"uname\00"
@.str.1 = [3 x i8] c"32\00"
@.str.2 = [3 x i8] c"64\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.utsname
%4 = bitcast %struct.utsname* %3 to i8*
%5 = call i32 @uname(%struct.utsname* %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 255)
unreachable
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = add nsw i64 %12, 3
%14 = tail call i8* @malloc(i64 %13)
%15 = tail call i32 @strcpy(i8* %14, i8* %11)
%16 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i8* @strstr(i32 %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%21 = tail call i32 @strcat(i8* %14, i8* %20)
%22 = tail call i8* @strchr(i8* dereferenceable(1) %14, i8 signext 47)
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %26
24: ; preds = %10
%25 = tail call i32 @execvp(i8* %14, i8** %1)
br label %28
26: ; preds = %10
%27 = tail call i32 @execv(i8* %14, i8** %1)
br label %28
28: ; preds = %26, %24
%29 = phi i32 [ %25, %24 ], [ %27, %26 ]
ret i32 %29
}